How to compute sum of two integers using bit wise NOT, XOR, AND,and OR operators, without using SHIFT operator (not using arithmetic operators as well)? Is it possible ?
Example C code:
int a = 5;
int b = 11;
int c = a ^ b;
int d = a & b;
int sum = ...
Let's take a = b = 1
. The result of this sum is sum = 2
. The binary representation of the inputs are 00000001
(let's have 8-bits for simplicity). The output is 00000010
. You can easily get the least significant bit, LSB = a0 XOR b0
, but to modify the bit number 1 you need a shift.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.