int x = 8 , int y = 6, sopln(x&y) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

int x = 8 , int y = 6, sopln(x&y)

Why is the answer 0......anyone can tell the reason

8th Dec 2021, 4:44 AM
Rahul Yadgire
2 Answers
+ 1
8 = 1000 in binary 6 = 0110 in binary & = 0000 in binary = 0 in decimal When you AND (&) 2 binary numbers the bits in each place are compared. If both bits are 1 then the resulting bit is 1, otherwise, 0. Table & | 0 | 1 ------------- 0 | 0 | 0 ‐---‐-------- 1 | 0 | 1
8th Dec 2021, 5:38 AM
ChaoticDawg
ChaoticDawg - avatar
0
& is AND operator, has not binary value 1000 0110 --------- 0000
10th Dec 2021, 1:09 PM
zemiak