C Programming - Bitwise Operators - Discussion


Bitwise can be used to perform addition and subtraction.

[A]. Yes
[B]. No

Answer: Option B


No answer description available for this question.

Cheran said: (Jul 13, 2011)  
Bitwise operators can be used for multiplication and division only.

Dmitri said: (Aug 26, 2011)  
If bitwise operators can't be used for addition or subtraction, why can the hardware do it? It uses boolean operations on individual bits...
Also try the following function (which does addition with bitwise operators):

int bitadd(int x, int y)
int z = 0, c;
do {
z = x ^ y;
c = (x & y) << 1;
x = z;
y = c;
} while (c);
return z;

Atul said: (May 29, 2012)  
A big circuit inside the computer is made up of adder and subtracters which can perform all the operations like addition, multiplication, subtraction and division so how it can't be performed Dmitri has given good example above.

David said: (Jan 10, 2014)  
Whoever wrote this should swot up of course you can do bitwise addition and subtraction.

unsigned int myAdd(unsigned int a, unsigned int b)
unsigned int carry = a & b;
unsigned int result = a ^ b;
while(carry != 0)
unsigned int shiftedcarry = carry << 1;
carry = result & shiftedcarry;
result ^= shiftedcarry;
return result;

Pranali said: (Apr 1, 2017)  
Please explain the answer in detail.

Saumya said: (Sep 22, 2017)  
The Answer should be A. Because we can perform addition as well as subtraction using bitwise XOR.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.