Bitwise AND: 2&4 = 0 why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Bitwise AND: 2&4 = 0 why?

Bitwise AND: 2&4 = 0 why?. If we manually convert 2 and 4 to binary and then multiply them we get answer 8.

12th Feb 2019, 12:55 PM
Susanta Paul
Susanta Paul - avatar
5 Answers
+ 8
Bitwise AND handle bytes to bit level remembering than: 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1 Then first transform the numbers into bits and procede with AND operation bit by bit: 2= 010 4= 100 ________ 000 = 0
12th Feb 2019, 1:01 PM
KrOW
KrOW - avatar
+ 3
You are mixing AND with mutliplication and they are not same.. AND is a boolean operation than apply only to booleans fields (like 1/0, true/false) It, in practice, return 1/true if and only if either values are 1/true else 0/false.
12th Feb 2019, 1:15 PM
KrOW
KrOW - avatar
+ 2
👍👍👍
12th Feb 2019, 1:18 PM
KrOW
KrOW - avatar
+ 1
Then what is this? 010 100 ________ 000 000* 010** ________ 01000
12th Feb 2019, 1:10 PM
Susanta Paul
Susanta Paul - avatar
+ 1
Ok thank you so much you have cleared all my doubts
12th Feb 2019, 1:17 PM
Susanta Paul
Susanta Paul - avatar