当前位置:网站首页>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
边栏推荐
猜你喜欢

Keil5中如何做到 0 Error(s), 0 Warning(s).

Avalanche problem and the use of sentinel

AfxMessageBox和MessageBox的用法
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

pytorch nn. AdaptiveAvgPool2d(1)

Home online shopping project

ASGNet论文和代码解读2

衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)

Explain spark operation mode in detail (local+standalone+yarn)

Edge Drawing: A combined real-time edge and segment detector 翻译
随机推荐
【伸手党福利】开发人员重装系统顺序
Include() of array
Promise中finally的用法
GCC usage, makefile summary
torch.histc
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
数组的includes( )
还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板
Go tool cli for command line implementation
网页不能右键 F12 查看源代码解决方案
Pyramid scene parsing network [pspnet] thesis reading
Leetcode: offer 59 - I. maximum value of sliding window
Ridge regression and lasso regression
Md5sum operation
Feign远程调用和Getaway网关
Clion and C language
ctfshow爆破wp
EDLines: A real-time line segment detector with a false detection control翻译
4、【WebGIS实战】软件操作篇——数据导入及处理
Listener listener