当前位置:网站首页>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
边栏推荐
- 不用加减乘除实现加法
- 用小程序的技术优势发展产业互联网
- leetcode 1482 猜猜看啊,这道题目怎么二分?
- Detailed explanation of ES6 deconstruction grammar
- [deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
- How to achieve 0 error (s) and 0 warning (s) in keil5
- IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
- BluePrism注册下载并安装-RPA第一章
- Finally in promise
- 后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
猜你喜欢
![[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st

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

Home online shopping project

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

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

TEC: Knowledge Graph Embedding with Triple Context

Cookie&Session

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

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

Redis tutorial
随机推荐
Nacos
Cookie&Session
Filter
JUC学习
Edge drawing: a combined real-time edge and segment detector
torch.histc
【伸手党福利】开发人员重装系统顺序
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
JS daily development tips (continuous update)
pytorch训练深度学习网络设置cuda指定的GPU可见
Leetcode 128 longest continuous sequence (hash set)
Feign远程调用和Getaway网关
C#实现基于广度优先BFS求解无权图最短路径----完整程序展示
C语言多线程编程入门学习笔记
Cookie&Session
实现pow(x,n)函数
静态库使用MFC和共享库使用MFC的区别
Take you through a circuit board, from design to production (dry goods)
idea插件备份表
Overview of EtherCAT principle