8
\$\begingroup\$

How do I find two's complement for hex F3A1?

First I converted the number to binary 1111 0011 1010 0001 and then I found two's complement 0000 1100 0101 1111 givin' as result 0C5F which differs from the answer in the book: 0A57

What I'm doing wrong?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You're not doing anything wrong. Your result is correct. \$\endgroup\$
    – stevenvh
    Commented May 18, 2012 at 4:40
  • 1
    \$\begingroup\$ That book's result is so off that I would suspect it may be the right answer to some other question (a question answer mixup). \$\endgroup\$
    – Kaz
    Commented May 18, 2012 at 6:18

3 Answers 3

5
\$\begingroup\$

Flip 1's to 0's and 0's to 1's (i.e. regular complement). Then add 1.

What you're doing wrong is having too much faith in a book.

But, on the bright side, at least it's some kind of technical book that is probably mostly correct.

\$\endgroup\$
5
  • \$\begingroup\$ i get the same result, maybe the book has a mistake \$\endgroup\$ Commented May 18, 2012 at 4:39
  • 2
    \$\begingroup\$ yep, just go into Windows 7, bring up the calculator, switch to Programmer under View, select Hex and Word mode, enter F3A1 and then press ±, result is C5F (doesn't display leading 0). \$\endgroup\$
    – tcrosley
    Commented May 18, 2012 at 5:15
  • \$\begingroup\$ @tcrosley - nonsense, you can do it on sight! :-) \$\endgroup\$
    – stevenvh
    Commented May 18, 2012 at 5:18
  • 1
    \$\begingroup\$ If this was comedians.stackexchange.com you I would vote for you as a moderator :) \$\endgroup\$
    – MikeJ-UK
    Commented May 18, 2012 at 9:41
  • \$\begingroup\$ @MikeJ-UK It took me a few minutes to get my own joke, looking at this over 8 years later. \$\endgroup\$
    – Kaz
    Commented Dec 17, 2020 at 16:54
14
\$\begingroup\$

If you're a bit acquainted with hex you don't need to convert to binary. Just take the base-16 complement of each digit, and add 1 to the result. So:
F - F = 0
F - 3 = C
F - A = 5
F - 1 = E

So you get 0C5E. Add 1 and here's your result: 0C5F.

\$\endgroup\$
1
\$\begingroup\$

for a faster approach you can also flip the bits left to very first set bit and find out the 2s complement(instead of finding 1ns and then adding 1 to it)

1111 0011 1010 0001 toggle the bits left to first set bit
0000 1100 0101 1111

i expect you would like this if bit pattern is changed to binary than hex :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.