1

I am learning bitwise operations and cannot figure out how 305419896 bitshifted right by 28 equals 1? Can someone explain this?

clever_trevor
  • 1,530
  • 2
  • 22
  • 42

2 Answers2

4

305419896 represented in binary is 1001000110100010101100111100 (thats 29 bits). If we take that value and shift all the bits right 28 places, we end up with just 1 (in binary and decimal).

andars
  • 1,384
  • 7
  • 12
2

You can think of >> n as a truncated division by 2^n.

305419896 / 2^28 -> 305419896 / 268435456 -> 1.1377777755260468

The decimal part is dropped, leaving you with 1.

Of course, as andars said, the computer does this by bit shifting.
Read this question for a good understanding.

Community
  • 1
  • 1
Prashant Kumar
  • 20,069
  • 14
  • 47
  • 63