for example, let's say: 0xE5

assume the system is 8 -bit in decimal it's = 229 and in Binary it's = 1110 0101

the Two's Complement rules said: sign-bit, which's the most left, indicates a negative value if it's "1", or if it's "0" the value is positive.

so, the value is positive, but the Binary representation indicates in left-most bit as "negative" value!

I'm totally confused... how can i show the correct representation in two's Complement format in 8-bit system?

  • $\begingroup$ Short answer is that you cannot. A signed 8-bit integer must fall into a limited range which excludes +229 from the possible values. Of course there is an unsigned 8-bit integer that could represent this value. $\endgroup$ – hardmath Feb 7 '16 at 19:33
  • 1
    $\begingroup$ With 8 bits, two's complement format can only represent integers in the range $-128$ to $+127$. You're trying to represent 0xE5 = 229. $\endgroup$ – fgp Feb 7 '16 at 19:34
  • $\begingroup$ does this equation always give the rage? : -2^[(n-bit) -1] to [2^(n-bit) -1] - 1] ? $\endgroup$ – Makaveli Feb 7 '16 at 19:40

When using 2-complementary, the range of 8 bits integer is $-128<= n <= 127$. When you have a number 0xE5, once it is binary form, it is a negative number. The two's complentary of this number is a positive number, and add negative sign to it, that is the decimal number (negative) for 0xE5 for the system using two's complementary.

once you flip bits, you should add 1 to it.

  • $\begingroup$ let's assume we upgrade the system to be 10-bit: is it correct to do this? 0 1110 0101, in order to show it's positive? $\endgroup$ – Makaveli Feb 7 '16 at 19:42
  • $\begingroup$ That's correct. But, when talking about two's complement, it is within the frame of the number of bits the system is using. You cannot use more bits than the system allow for an integer type. $\endgroup$ – runaround Feb 7 '16 at 19:45
  • $\begingroup$ ok! thanks runaround!! $\endgroup$ – Makaveli Feb 7 '16 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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