Check if two hexadecimal numbers are complementary in a location of a given number of bytes.

binary

Check, using complementary code rules, if:

  • if $(9A7D)_{16}$ and $(7583)_{16}$ are complementary in a location of $2$ bytes
  • if $(000F095D)_{16}$ and $(FFF0F6A3)_{16}$ are complementary in a location of 4 bytes

I am not sure what the problem statement means exactly. What am I supposed to check? In the case of the first subpoint, I converted the two numbers into binary to see if they are complementary over a location of $16$ bits ($2$ bytes). Again, I have no idea if I am supposed to do this.

$$ (9A7D)_{16} = 1001 \hspace{0.1cm} 1010 \hspace{0.1cm} 0111 \hspace{0.1cm} 1101 _ {2} $$

$$ (7583)_{16} = 0111 \hspace{0.1cm} 0101 \hspace{0.1cm} 1000 \hspace{0.1cm} 0011 _ {2} $$

But in order for the two to be complementary in a location of $2$ bytes we would need the two numbers to be complementary as a whole, since the whole number representations have $2$ bytes. This looks to be false. The second subpoint of the problem reaches the same conclusion. This is what I don't think that it's right what I'm doing. It doesn't feel like I did much. So what exactly is the problem statement asking for?

Best Answer

The problem is asking to check the two values using 1's complement and 2's complement rules.

To calculate 1's complement, subtract each digit from $15\space(=F_{16})$.

To calculate 2's complement, add 1 to one's complement.

$1$'s complement of $9A7D_{16} = 6582_{16}$ and not $7583_{16}$

$2$'s complement of $9A7D_{16} = 6582_{16} + 1 = 6583_{16}$ which is also not $7583_{16}$.

So, the values are neither one's complements not two's complements of each other.

Repeat the same for the 4 byte value. A cursory check shows they are 2's complements of each other.

Related Question