binarytwos-complement8-bit# How to differentiate +128 from -128 in an 8-bit memory location in binary representation when their representation is the same?

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...

Solution

8_{10} bits can represent 2_{10}^{810} = 256_{10} different values. The range from -128_{10} to +128_{10} contains 25**7**_{10} different values.

It is impossible to represent the full range of integers from -128_{10} to +128_{10} in 8_{10} bit. You will have to remove *at least one* integer from that range.

In other words: +128_{10} *cannot* be represented in 8_{10} 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.

- Length filter for list not working correctly
- Using reinterpret_cast<> to write in binary to a file
- How to remove trailing zeros from a binary number
- Count ones in a segment (binary)
- Correct use of getUint16()
- Converting from an integer to its binary representation
- inserting in binary tree doesn't work using java
- python: c# binary datetime encoding
- How to get only the first ten bytes of a binary file
- Difference between machine language, binary code and a binary file
- Why does Git treat this text file as a binary file?
- Override git's choice of binary file to text
- Distributing a statically linked ELF 32bit Binary - Will it run on all platforms?
- Statically Linked ELF 32 bit Binary - Distro Specific
- Translation from Binary to Decimal
- Calculating the total number of possibilities in binary?
- Regular Expression for Binary Numbers Divisible by 5
- How to check code generated by C++ compiler?
- What is the algorithm of Skeleton
- Setting all bits before first '1'
- Bitmasking conversion of CPU ids with Go
- Custom decode binary data in polars
- Why console.log shows only part of the number resulting from 0.1+0.2=0.30000000000000004
- Unable to properly return python data in function
- Word to represent 5 bits of data?
- How to convert text to binary code in JavaScript?
- Can I use a binary literal in C or C++?
- Reading integers from binary file in Python
- Way to add leading zeroes to binary string in JavaScript
- base conversion in c programming language