Details will be announced on the course website.
Today:Number Systems
Every layer stores its data as bits (0s and 1s).
SI100B · Electrical Engineering
Xin Lou
School of Information Science and Technology · Fall 2026(456)_{10} = 4\times 10^2 + 5\times 10^1 + 6\times 10^0
(3705.86)_{10} = 3\times 10^3 + 7\times 10^2 + 0\times 10^1 + 5\times 10^0 + 8\times 10^{-1} + 6\times 10^{-2}
Decimal uses 10 symbols (0–9); digits right of the point have negative powers of 10.


An integer with a fixed scaling factor (r^{-M}); hardware prefers fixed point for higher speed and lower cost.
Sign and magnitude
One’s complement
Two’s complement
All three represent positive numbers in the same way.
columns: [{width: 0.18}, {width: 0.30}, {width: 0.38}]
| Operation | Direct binary addition | Compare and subtract |
|---|---|---|
| 4 + (−3) = 1 | 0100 + 1011 = 1111 ( − 7) |
0100 - 0011 = 0001 ( + 1) |
| − 4 + 3 = − 1 | 1100 + 0011 = 1111 ( − 7) |
-(0100 - 0011) = 1001 ( − 1) |
Direct addition fails (4 - 3 \neq 4 + (-3)); hardware must compare signs and magnitudes.
\underbrace{0111}_{+7} \;\xrightarrow{\text{invert}}\; \underbrace{1000}_{-7}
Invert every bit to negate; +0 = \texttt{0000} and -0 = \texttt{1111} still give two zeros.
columns: [{width: 0.22}, {width: 0.34}, {width: 0.30}]
| Operation | 4-bit addition | End-around carry |
|---|---|---|
| 4 + 3 = 7 | 0100 + 0011 = 0111 |
none ( + 7) |
| 4 + (−3) = 1 | 0100 + 1100 = 1 0000 |
0000 + 1 = 0001 ( + 1) |
| − 4 + 3 = − 1 | 1011 + 0011 = 1110 |
none ( − 1) |
If addition produces a carry out, add 1 back to the least significant bit (end-around carry).
\underbrace{0111}_{+7} \;\xrightarrow{\text{invert}}\; 1000 \;\xrightarrow{+1}\; \underbrace{1001}_{-7}
Invert the bits and add one to form the negative.
\text{value}=-b_{n-1}2^{n-1}+\sum_{i=0}^{n-2}b_i2^i \qquad (b_i\in\{0,1\})
(1001)_2=-8+1=-7
The most significant bit has negative weight.
columns: [{width: 0.28}, {width: 0.20}, {width: 0.14}, {width: 0.24}]
| 5-bit addition | Mathematical sum | 5-bit reading | Carry into / out of MSB |
|---|---|---|---|
01011 + 01001 = 10100 |
11 + 9 = 20 | − 12 | 1/0 |
00011 + 01001 = 01100 |
3 + 9 = 12 | 12 | 0/0 |
Two positive numbers overflow when the sum is negative.
columns: [{width: 0.28}, {width: 0.20}, {width: 0.14}, {width: 0.24}]
| 5-bit addition | Mathematical sum | 5-bit reading | Carry into / out of MSB |
|---|---|---|---|
10011 + 11001 = 01100 |
− 13 + (−7) = − 20 | 12 | 0/1 |
11011 + 11001 = 10100 |
− 5 + (−7) = − 12 | − 12 | 1/1 |
Two negative numbers overflow when the sum is nonnegative.
\underbrace{01001}_{+9}+\underbrace{11011}_{-5} =\underbrace{00100}_{+4} \qquad (\text{5 bits})
Adding numbers of opposite signs cannot overflow.
\boxed{\text{overflow}\;\Longleftrightarrow\; \text{carry into MSB}\ne\text{carry out of MSB}}
For signed two’s-complement addition at a fixed width.
columns: [{width: 0.26}, {width: 0.38}, {width: 0.2}]
| 4-bit value | Extend to 6 bits | Value |
|---|---|---|
0101 |
000101 |
+ 5 |
1011 |
111011 |
− 5 |
Copy the sign bit to the left; the value stays the same.
columns: [{width: 0.28}, {width: 0.44}, {width: 0.14}]
| Extend before adding | 6-bit addition | Result |
|---|---|---|
− 5: 1011 → 111011 |
111011 + 010010 = 001101 |
13 |
Discard the carry out; -5 + 18 = 13.

\text{stored exponent}=\text{exponent}+127
-3+127=124=(01111100)_2
FP32 stores the exponent with a bias of 127.
1.011_2=1+2^{-2}+2^{-3}=1.375
For a normal number, the leading 1 is implicit; the fraction field stores 01100…0.
6.5=110.1_2=1.101_2\times2^2
columns: [{width: 0.2}, {width: 0.24}, {width: 0.40}]
| Sign (1 bit) | Exponent (8 bits) | Fraction (23 bits) |
|---|---|---|
0 |
10000001 |
10100000000000000000000 |
The exponent is 2+127=129; the leading 1 is implicit.




columns: [{width: 0.22}, {width: 0.32}, {width: 0.32}]
| 32-bit format | Smallest / Largest positive | Dynamic range |
|---|---|---|
| Fixed point | 1 × 2−N to (232−1) × 2−N | 20log10(232−1) ≈ 192 dB |
| Floating point | ≈ 1.18 × 10−38 to 3.40 × 1038 | ≈ 1529 dB |
Floating point trades hardware simplicity for a vastly wider dynamic range.
columns: [{width: 0.16}, {width: 0.70}]
| Format | Characteristics & example |
|---|---|
| Fixed point | Limited dynamic range, fast, low power (e.g., filter coefficient quantization) |
| Floating point | High dynamic range, complex, slow |
Hardware uses fixed point when range is bounded and cost or power matters.

Everything is stored as bits.
The same bits can have different meanings.
A fixed number of bits means a limited range.
Floating point uses scientific notation, with rounding.
Fewer bits per parameter means smaller models.
Details will be announced on the course website.
1111_2 - y = (2^4 - 1) - y
1111_2 - 0111_2 = 1000_2 \equiv -7_{10}
For a 4-bit positive number y, its bitwise complement equals (2^4 - 1) - y.
x + ((2^4 - 1) - y) = (2^4 - 1) + (x - y)
If x < y, there is no carry and the sum is the one’s complement of x - y; if x > y, the carry triggers end-around carry (-2^4 + 1), leaving x - y; if x = y, the sum is 1111_2 (-0).
-y \equiv 2^b - y \pmod{2^b}
Adding 1 to the one’s complement (2^b - 1) - y gives 2^b - y; dropping the carry out of a b-bit adder computes \bmod\; 2^b.
x + (2^b - y) = 2^b + (x - y)
If x \ge y, the carry out (2^b) is dropped, leaving x - y; if x < y, there is no carry and 2^b - (y - x) is the two’s complement of x - y (assuming no overflow).