Khan
Khan

Reputation: 185

Bit-wise operations on addresses

I have to solve a question saying

The value of ab if ab & 0x3f equals 0x27.

For solving,I assumed let ab be 0xMN and then N&f means N&1111 but here book says that N&1111 should yield 0111 i.e. 7 =>N should be 7. Similarly how M&0011should yield 2the book says without telling how.

This maybe quite a simple to you people but i tried didn't succeed so here.

Upvotes: 0

Views: 200

Answers (1)

shree.pat18
shree.pat18

Reputation: 21757

Think of it this way - a bit can only have 2 possible values i.e. 0 or 1. If you write down the binary representations, you will end up with something like the below:

  abcd efgh
& 0011 1111
-----------
= 0010 0111

Going by the definition of bitwise AND, the values of a to h that would give the below result are 0,0,1,0,0,1,1,1 respectively. Converting back to hexadecimal, the value is 0x27.

As @jlahd points out in the comments below, three more values can satisfy this equation : 0x67, 0xa7 and 0xe7. This is because x&0 = 0 so that a and b in the above could take any possible values without affecting the outcome.

Upvotes: 1

Related Questions