当前位置:网站首页>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
边栏推荐
- 后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
- 静态库使用MFC和共享库使用MFC的区别
- Hello World generation
- 串口接收数据方案设计
- How to use hybrid format to output ISO files? isohybrid:command not found
- About the application of MySQL
- JS daily development tips (continuous update)
- Design of serial port receiving data scheme
- 数组的includes( )
- Research on target recognition and tracking based on 3D laser point cloud
猜你喜欢

还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

JUC learning

E15 solution for cx5120 controlling Huichuan is620n servo error

监听器 Listener

EDLines: A real-time line segment detector with a false detection control翻译

小程序容器技术与物联网IoT的结合点

雪崩问题以及sentinel的使用

The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)

文件上传下载
随机推荐
Server rendering technology JSP
在线公网安备案保姆级教程【伸手党福利】
pytorch nn. AdaptiveAvgPool2d(1)
文件上传下载
Pyramid Scene Parsing Network【PSPNet】论文阅读
JUC learning
串口接收数据方案设计
ctfshow爆破wp
Overview of EtherCAT principle
TEC: Knowledge Graph Embedding with Triple Context
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
二叉树神级遍历:Morris遍历
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
Edlines: a real time line segment detector with a false detection control
split(),splice(),slice()傻傻分不清楚?
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
多元线性回归
【读书笔记】《文案变现》——写出有效文案的四个黄金步骤
C语言多线程编程入门学习笔记
岭回归和lasso回归