0

In an 8-bit memory location, the integer +128 is 10000000 but also using two's complement method -128 integer is represented as 10000000.

I find this weird. Why is +128 or 128(unsigned) represented as 10000000? The leftmost bit is 1, and this means that it is negative where in fact it is positive...

user134613
  • 109
  • 4
  • 1
    i dont understand your question. you mix two things up: two's complement and unsigned numbers. they are two different things – Raildex Feb 20 '21 at 11:18

1 Answers1

2

810 bits can represent 210810 = 25610 different values. The range from -12810 to +12810 contains 25710 different values.

It is impossible to represent the full range of integers from -12810 to +12810 in 810 bit. You will have to remove at least one integer from that range.

In other words: +12810 cannot be represented in 810 bit two's complement binary representation.

In an 8-bit memory location, the integer +128 is 10000000

That is correct. However, when you use all 8 bits to represent positive numbers, then you simply cannot represent negative numbers at all.

but also using two's complement method -128 integer is represented as 10000000.

That is also correct.

I find this weird. Why is +128 or 128(unsigned) represented as 10000000?

They are two different representations.

The leftmost bit is 1, and this means that it is negative where in fact it is positive...

It only means that it is a negative number in two's complement representation. But it is not two's complement representation. It is simple binary representation.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • So, since the range from -128 to +128 is greater than 256, then the number 128 can't be represented in an 8-bit memory. So, if we had an 8-bit memory, then the integer 128 can't be stored whether its positive or negative. But, if its 9-bit memory then it would be 010000000 and it can be stored. And the negative number is 110000000 and can be stored. So, in an 8-bit memory, 10000000 is 128 if its a simple representation, but if we are considering two's complement then it has no meaning or it just doesn't exist. Did I understand well? – user134613 Feb 20 '21 at 11:50
  • 1
    8 bit can represent up to 256 different "things". It is totally up to you how you choose those up to 256 "things" and how you encode them. You can certainly encode the integers -127 to +127, because those are 255 different integers. You can also encode -128 to +127 or -127 to +128. You can encode all even integers from 1000 to 1510. It is all up to you. – Jörg W Mittag Feb 20 '21 at 11:52
  • 1
    It would be interpreted as whatever you program the computer to interpret it. It could +128. It could be -128. It could be +1000. It could be donut. – Jörg W Mittag Feb 20 '21 at 11:56
  • +1000 is 1111101000 and its 10 bit so how can it be represented in an 8-bit? Unless the computer takes only 8 bit out of it and cancel the rest of bits – user134613 Feb 20 '21 at 12:03
  • How could the computer interpret 10000000 as +1000? – user134613 Feb 20 '21 at 12:22
  • 1
    By you programming it to interpret it that way. A computer simply does what you tell it to. If you tell it to interpret 10000000 as +128, it will do that. If you tell it to interpret 10000000 as -128, it will do that. If you tell it to interpret 10000000 as +1000, it will do that. If you tell it to interpret 10000000 as a donut, it will do that. – Jörg W Mittag Feb 20 '21 at 12:26
  • Oh okay. Thank u so much :) :) – user134613 Feb 20 '21 at 12:32