0

I have a number in base $10$. The number is $N$. $N=-127$. Assuming $16$ bit 2's complement number representation, I need to convert $N$ to hexadecimal

I am not sure how to proceed. I know that the binary representation of $-127$ is $1000000001111111$. I am confused as to what the question is asking. Please help. Sorry for the tag.

Travis Willse
  • 99,363

1 Answers1

3

Your expression for $-127$ is the sign-magnitude representation, not the two's complement representation. To get two's complement, you start with the representation for $+127$, which in $16$ bits is $0000\ 0000\ 0111\ 1111$. To negate it you complement each bit, getting $1111\ 1111\ 1000\ 0000$ and add $1$ to get $1111\ 1111\ 1000\ 0001$. Note that you can now add $127+(-127)$ and get $0$ if you ignore the carry out. That is one of the nice things about two's complement.

To convert this to hex, you can just convert each set of four bits, so the hex representation is $FF81$

Ross Millikan
  • 374,822
  • So basically in this question I had to find the 2's complement representation of the number and then convert that to hexadecimal. Thanks man for the answer . I was confused when I saw the question. An upvote and an accept. – The Learner Oct 01 '19 at 05:31