当前位置:网站首页>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
边栏推荐
- 深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
- 在 C 中声明函数之前调用函数会发生什么?
- Kmeans
- How do I use Google Chrome 11's Upload Folder feature in my own code?
- Hal library setting STM32 interrupt
- Test function in pychram
- Avalanche problem and the use of sentinel
- torch.histc
- Include() of array
- Ultimate dolls 2.0 | encapsulation of cloud native delivery
猜你喜欢

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
![Pyramid scene parsing network [pspnet] thesis reading](/img/05/4645c8a595083479dee6835620335d.png)
Pyramid scene parsing network [pspnet] thesis reading

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

Take you through a circuit board, from design to production (dry goods)

Learning notes for introduction to C language multithreaded programming

Overview of EtherCAT principle

File upload and download

Data exchange JSON

Ctfshow blasting WP

Cookie&Session
随机推荐
终极套娃 2.0 | 云原生交付的封装
排序链表(归并排序)
FCN全卷积网络理解及代码实现(来自pytorch官方实现)
Leetcode 1482 guess, how about this question?
Detailed explanation of ES6 deconstruction grammar
线程数据共享和安全 -ThreadLocal
Basic concepts of database
Redis tutorial
Force buckle - sum of two numbers
ECMAScript 6.0
5、【WebGIS实战】软件操作篇——服务发布及权限管理
在线公网安备案保姆级教程【伸手党福利】
Listener listener
Let's just say I can use thousands of expression packs
TEC: Knowledge Graph Embedding with Triple Context
Subnet division (10)
split(),splice(),slice()傻傻分不清楚?
Home online shopping project
文件上传下载
pytorch nn. AdaptiveAvgPool2d(1)