当前位置:网站首页>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
边栏推荐
- Home online shopping project
- JS daily development tips (continuous update)
- Leetcode: offer 59 - I. maximum value of sliding window
- [nine day training] content III of the problem solution of leetcode question brushing Report
- Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
- Cookie&Session
- pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
- Leetcode 1818 absolute value, sorting, dichotomy, maximum value
- 5. [WebGIS practice] software operation - service release and permission management
- 二叉树神级遍历:Morris遍历
猜你喜欢

5、【WebGIS实战】软件操作篇——服务发布及权限管理

后台系统右边内容如何出现滚动条和解决双滚动条的问题

Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C

FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)

Detailed list of errors related to twincat3 ads of Beifu

Pyramid Scene Parsing Network【PSPNet】论文阅读

Depth first traversal of C implementation Diagram -- non recursive code

pytorch nn.AdaptiveAvgPool2d(1)

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)

Listener listener
随机推荐
Split(), split(), slice(), can't you tell?
md5sum操作
How to use hybrid format to output ISO files? isohybrid:command not found
Hal library operation STM32 serial port
TEC: Knowledge Graph Embedding with Triple Context
Pytest -- plug-in writing
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
Edge drawing: a combined real-time edge and segment detector
雪崩问题以及sentinel的使用
Valid brackets (force deduction 20)
Hello World generation
多元线性回归
pytorch训练深度学习网络设置cuda指定的GPU可见
AfxMessageBox和MessageBox的用法
Depth first traversal of C implementation Diagram -- non recursive code
Gorilla/mux framework (RK boot): RPC error code design
10、Scanner.next() 无法读取空格/indexOf -1
岭回归和lasso回归
【伸手党福利】开发人员重装系统顺序
GCC usage, makefile summary