Intro
Computers store all information using binary, a base-2 numbering system using only 0 and 1.
- Each digit in binary is called a bit (binary digit).
Unsigned and Signed Integers
Unsigned Integers
- Only represent non-negative numbers.
- Maximum value depends on the number of bits:
| Bytes | Type | Bits | Min Value | Max Value |
| ----- | -------- | ---- | --------- | -------------------------- |
| 1 | `uint8` | 8 | 0 | 255 |
| 2 | `uint16` | 16 | 0 | 65,535 |
| 4 | `uint32` | 32 | 0 | 4,294,967,295 |
| 8 | `uint64` | 64 | 0 | 18,446,744,073,709,551,615 |Signed Integers
- Can represent negative numbers, usually using two’s complement.
- Max and min values:
| Bytes | Type | Bits | Min Value | Max Value |
| ----- | ----- | ---- | -------------------------- | ------------------------- |
| 1 | int8 | 8 | -128 | 127 |
| 2 | int16 | 16 | -32,768 | 32,767 |
| 4 | int32 | 32 | -2,147,483,648 | 2,147,483,647 |
| 8 | int64 | 64 | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
Converting Between Binary and Decimal
Binary Number Decimal Number Hex Number 0 0 0 1 1 1 10 2 2 11 3 3 100 4 4 101 5 5 110 6 6 111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F 10000 16 10 10001 17 11 10010 18 12 10011 19 13 10100 20 14 10101 21 15 10110 22 16 10111 23 17 11000 24 18 11001 25 19 11010 26 1A 11011 27 1B 11100 28 1C 11101 29 1D 11110 30 1E 11111 31 1F 100000 32 20 1000000 64 40 10000000 128 80 11111111* 255 FF 100000000 256 100 Notes:
- Binary is the fundamental representation for all data in computers
- Hexadecimal (base-16) is often used as a shorthand for binary because 4 bits = 1 hex digit.
*See Worked Example: Hex ↔ Binary ↔ Decimal for a full 8-bit conversion.
Decimal → Binary
- Divide the decimal number by 2 repeatedly, writing down the remainder each time.
- The binary number is the remainders read from bottom to top.
Example: Convert 13 to binary:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Binary: 1101
Binary → Decimal
- Multiply each bit by 2^(position from right, starting at 0) and sum them.
Example: Convert 1101 to decimal:
1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 = 8 + 4 + 0 + 1 = 13




