-1

I have two numbers, 2147483648 and 808529920 stored in unsigned int variables but, when I do their bitwise and in C, the answer is supposed to be 1, but I get 0.

808529920 in binary looks like:

110000001100010011000000000000

2147483648 in binary looks like:

10000000000000000000000000000000
unsigned int a = 808529920;
unsigned int b = 2147483648;

unsigned int ret = a & b;
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 4
    Don't just describe the code in words. Show the exact code as a [minimal verifiable example](https://stackoverflow.com/help/minimal-reproducible-example). That is, show a small bit of complete code that anyone can copy exactly as shown to reproduce the problem. – kaylum Oct 18 '20 at 03:06
  • 2
    `answer supposed to be 1` ... who says? – jsotola Oct 18 '20 at 03:11
  • 2
    We have two even numbers here, their intersection (bitwise AND) is for sure even as well. – harold Oct 18 '20 at 03:12
  • `110000001100010011000000000000` is only 30 bits. The full 32-bit integer is `00110000001100010011000000000000` – kaylum Oct 18 '20 at 03:17
  • Thanks! I just use python format to see the binary type, so I didn't realize it only show me 30 bits. – user9188191 Oct 18 '20 at 03:20

1 Answers1

3
 808529920 == 0b00110000001100010011000000000000
2147483648 == 0b10000000000000000000000000000000

There are no bits in common, so you should get 0 not 1.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173