当前位置:网站首页>Addition without addition, subtraction, multiplication and division
Addition without addition, subtraction, multiplication and division
2022-07-01 03:36:00 【Enthusiastic citizen Mr. Xue】

Bit operation is used here ,a+b The result of no carry and a^b equal ,0 + 1 = 1 == 0 ^ 1 = 1
a+b The carry of is equal to (a&b) << 1 3+1 The carry of is (11 & 1) << 1 = 10
public int add(int a, int b) {
// Carry is 0 Jump out when
while(b != 0){
// carry
int c = (a & b) << 1;
// No carry and
a = a^b;
// carry
b = c;
}
return a;
}
operation 3+1:
1 != 0 Into the loop carry c = (11 & 1) << 1 = 10
a = 11 ^ 1 = 10
b = 10The second cycle 10 != 0
c = (10 & 10) << 1 = 100
a = 10 ^ 10 = 0
b = 100The third cycle 100 ! = 0
c = ( 0 & 100) << 1 = 0
a = a ^ 100 = 100
b = 0;end The result is 4
边栏推荐
- pytorch nn. AdaptiveAvgPool2d(1)
- C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
- Detailed list of errors related to twincat3 ads of Beifu
- Server rendering technology JSP
- Nacos
- 二叉树神级遍历:Morris遍历
- shell脚本使用两个横杠接收外部参数
- 打包iso文件的话,怎样使用hybrid格式输出?isohybrid:command not found
- Test function in pychram
- Feature pyramid networks for object detection
猜你喜欢

idea插件备份表

ASGNet论文和代码解读2

Edge drawing: a combined real-time edge and segment detector

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
![5. [WebGIS practice] software operation - service release and permission management](/img/5d/070e207bd96e60ba1846d644d4fb54.png)
5. [WebGIS practice] software operation - service release and permission management

监听器 Listener
![[us match preparation] complete introduction to word editing formula](/img/e4/5ef19d52cc4ece518e79bf10667ef4.jpg)
[us match preparation] complete introduction to word editing formula

Data exchange JSON

还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板
![[nine day training] content III of the problem solution of leetcode question brushing Report](/img/7e/1e76181e56ef7feb083f9662df71c7.jpg)
[nine day training] content III of the problem solution of leetcode question brushing Report
随机推荐
Server rendering technology JSP
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
shell脚本使用两个横杠接收外部参数
Pyramid scene parsing network [pspnet] thesis reading
Kmeans
在线公网安备案保姆级教程【伸手党福利】
Feature Pyramid Networks for Object Detection论文理解
LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
Feign remote call and getaway gateway
Hal library setting STM32 interrupt
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
The combination of applet container technology and IOT
打包iso文件的话,怎样使用hybrid格式输出?isohybrid:command not found
实现pow(x,n)函数
TEC: Knowledge Graph Embedding with Triple Context
[us match preparation] complete introduction to word editing formula
multiple linear regression
go实现命令行的工具cli
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动