The short answer
The bit pattern 11111111 is 255 when you read it as an unsigned 8-bit number. Read it as a signed 8-bit number in two’s complement, which C++20 requires for signed integers, and it is -1. The bits alone don’t settle the question. The type you read them with decides the value.
Reading the leftmost bit
In two’s complement, the leftmost bit is the sign bit. If it is 0, the number is zero or positive, and the other bits are read as usual. If it is 1, the number is negative. To find its value, read all the bits as unsigned and subtract 2 to the power of 8, which is 256.
For 11111111, that works out to 255 - 256 = -1.
You can check it another way. Add 1 to 11111111 and the result needs nine bits, 100000000. A byte holds only eight bits, so the leftmost bit is dropped and what remains is 00000000, which is zero. Adding 1 to -1 also gives 0, so the two readings agree.
Some 8-bit values side by side
| Bit pattern | Unsigned | Signed (two’s complement) |
|---|---|---|
| 00000000 | 0 | 0 |
| 01111111 | 127 | 127 |
| 10000000 | 128 | -128 |
| 11111110 | 254 | -2 |
| 11111111 | 255 | -1 |
The signed column climbs to 127 and then drops to -128. That is the point where the sign bit turns on.
Other ways to store negatives
Before C++20, the standard also allowed other ways to store negative numbers. Sign-magnitude reads 11111111 as -127, and ones’ complement reads it as -0. Some older or specialized hardware used those schemes. Modern C++ requires two’s complement, so for signed 8-bit numbers the answer in current code is -1.
Checking it in C++
#include <bitset>
#include <cstdint>
#include <iostream>
int main() {
std::uint8_t as_unsigned = 0b11111111; // 255
std::int8_t as_signed = -1; // stored as 11111111
std::cout << static_cast<int>(as_unsigned) << '\n'; // 255
std::cout << static_cast<int>(as_signed) << '\n'; // -1
std::cout << std::bitset<8>(as_signed) << '\n'; // 11111111
}
The output is:
255
-1
11111111
The static_cast<int> calls are needed because std::int8_t is a character type on most systems. Printing it directly would show a character instead of a number.
Why the reading matters
Code that treats a byte as signed when it was meant to be unsigned can turn 255 into -1. This can happen when raw bytes come from files, network data or hardware. Use std::uint8_t for raw bytes, and convert to a signed type only on purpose.
If the general idea of signed and unsigned is new, the article on what does signed and unsigned mean in binary covers that first. For the wider picture of signed vs unsigned in c, including ranges and comparison rules, read the main guide to signed and unsigned integers in C++.