0
$\begingroup$

The Problem Convert 256 to its 2's complement representation.

My Work

   I know that 256's representation in unsigned binary is 100000000. What I know from working with two's complement model is that the most significant digit represents the sign of the number. So in this case, 100000000 cannot be 2's complement representation as well because that would mean that the original number, 256 is negative.

   Is there a specified number of zeros I should add to the front of the binary representation? Would it be acceptable to just add one zero to the front, say 0100000000?

$\endgroup$

1 Answer 1

2
$\begingroup$

Two's complement is a representation of a number. Using different bases, encodings, a number (as a mathematical object) can be represented in many ways.

There is no "specified number of zeros". It is rather than, if you have 10 bits, they can represent 1024 values. It can be unsigned numbers between 0 and 1023 It can be signed numbers between -512 and +511 if you use two's complement.

"0100000000" is indeed 256 both as unsigned and two's complement signed 10 bits numbers.

$\endgroup$
2
  • $\begingroup$ But 100000000 would be 256 as unsigned but not 256 two's complement. So you you need to add zeros to the front of 100000000. I was just wondering how many is standard? I guess it doesn't matter. It's all the same. $\endgroup$ Apr 5, 2015 at 19:00
  • $\begingroup$ There is no standard. Usually, computers deal with 8bits, 16bits, 32bits numbers. When converting between sizes, for example 8bits to 16bits, the MSB is repeated for two's complement, and zeros are added on the left for unsigned numbers. $\endgroup$
    – Grabul
    Apr 5, 2015 at 19:50

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.