0
uint16_t a = 0x00 << 8 + 0xB9;
printf("%d",a);

I'm expecting 185 as an output but I'm getting 0.

What is happening here?

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37

1 Answers1

5

If you look at this link, you'll see that the order of precedence means that the addition is performed before the shift. Change your code to

uint16_t a = (0x00 << 8) + 0xB9;
printf("%d",a);

to see the desired behaviour.

Benjamin James Drury
  • 2,353
  • 1
  • 14
  • 27