What does 0fh mean?

user2149780 picture user2149780 · Jul 9, 2013 · Viewed 9.6k times · Source

I am trying to do

and eax, 0fh

and I know 0fh means 15. From

and eax, 0fh

I am supposed to clear all but the last 4 bits of eax. I don't understand how you get (32-4)=28 bits of 1 and 4 0s.

Answer

Matteo Italia picture Matteo Italia · Jul 9, 2013

15 in binary is 1111 (in facts 15=8+4+2+1); adding the padding zeroes to reach 32 bits (the width of eax) we get

00000000000000000000000000001111

Now, if you do a binary and with the content of eax, obviously you clear all the bits of eax but the last 4, since the zeroes "kill" whatever digit is in the corresponding position, while the ones let it "survive".

  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AND
  00000000000000000000000000001111
----------------------------------------
  0000000000000000000000000000xxxx