bit-manipulationcomplement

Why is the 4s-complement of 412 (in decimal) 321210?


I used an online converter to convert 412 from decimal to base 4 (which is 12130), and then applied the r's complement formula to get its 4s complement (which is 21210). However, in 6bits, 21210 becomes 321210.

When I try to convert it to decimal by doing
3 x - 4^5 + 2 x 4^4 + 1 x 4^3 + 2 x 4^2 + 1 x 4^1,
I get a number in decimal that is way larger than 412.


Solution

  • You have your "conversion to decimal" wrong -- it should be:

    -1 x 4^5 + 2 x 4^4 + 1 x 4^3 + 2 x 4^2 + 1 x 4^1
    

    note the difference in the first term, dealing with the sign -- the '3' digit has a value of -1 in a 4s complement sign digit.