Main Site Documentation

Bitshifting and others


#1

Guys,

can someone let me know the result of the following:

0x80C7 | (4 << 4)

and if possible explain to me how that works? I can’t get it into my dumb head :-[

Thanks in advance


#2

0x80C7


#3

Calculator application on Windows and Mac has a “Programmer” mode which will make your life easier in the situations like this. ;D

Explanation:

  1. First we need to shift 4 (binary 0000 0100) by 4 spaces to the left = 64 (binary 0100 0000)
  2. Now we need to do bitwise OR with 0x80C7 (bnary 1000 0000 1100 0111). As you can see both numbers have 1 in the 7th bit. So the result is 0x80C7