How fixed strings of bits encode signed whole numbers (two's complement) and real numbers (IEEE 754).
A computer stores every number as a fixed-width string of bits, so before the bits mean anything you need an agreed *encoding*. Whole numbers use two's complement; numbers with a fractional part use IEEE 754 floating point. Both are just rules for reading a bit pattern as a value.
In an n-bit two's complement number the bits keep their normal place values except the top (most-significant) bit, which counts as negative. For 8 bits the weights are -128, 64, 32, 16, 8, 4, 2, 1. That single change is the whole trick: because the sign bit carries a real negative weight, the *same* binary adder that adds unsigned numbers also adds signed ones correctly — no separate subtract hardware.
+5 = 00000101 negates to 11111010 + 1 = 11111011 = -5. Check it: -128 + 64 + 32 + 16 + 8 + 2 + 1 = -5.An n-bit two's complement value ranges from -2^(n-1) to 2^(n-1) - 1 — for 8 bits that is -128 to +127. The asymmetry (one more negative than positive) exists because there is a single zero, unlike older schemes.
A 32-bit float splits into three fields: 1 sign bit, an 8-bit exponent stored with a bias of 127, and a 23-bit mantissa (fraction). The value is (-1)^sign × 1.mantissa × 2^(exponent - 127). The leading 1. is implicit — it is never stored, which buys one extra bit of precision for free.
Encode -6.5 as a 32-bit float:
6.5 in binary = 110.1
normalize = 1.101 × 2^2
sign = 1 (negative)
exponent = 2 + 127 = 129 = 10000001
mantissa = 101 0000... (23 bits, leading 1 dropped)
1 10000001 10100000000000000000000 = 0xC0D000001.f × 2^e so there is a single 1 before the point.e + 127 (the bias) as the 8-bit exponent.f in the 23-bit mantissa; the leading 1 is dropped.0.5 has true exponent -1, stored as 126. This also makes float comparison work as if the bits were plain integers.