Binary numbers, how I can use bitmasks to certain bits?

199 views Asked by At

I have this example:

If we take the binary representation of the decimal value 220 (1101 1100) and we wanted to extract the higher 4 bits, we could use a bitmask with the boolean AND operation:

      1101 1100 (220)
 AND  1111 0000 (240)
      _________
      1101 0000 (208)

I need to know how to get 240.

1

There are 1 answers

0
Ludwig Schulze On
2**7 + 2**6 + 2**5 + 2**4 = 240

Where ** is exponentiation.