Every number in a computer is ultimately a sequence of 1s and 0s. Understanding binary — and its more human-friendly cousin hexadecimal — unlocks a clearer mental model of how computers store, process, and communicate data.
Why computers use binary
Computers are built from transistors — tiny electronic switches with two states: ON and OFF. This physical two-state reality maps directly to binary: 1 represents ON (high voltage), 0 represents OFF (low voltage).
Higher-level number systems like decimal and hexadecimal are human-friendly ways of reading and writing the same underlying binary data.
The four number systems
Decimal (base 10)
The system humans use. Ten digits: 0–9. Each position is a power of 10.
173 = (1 × 100) + (7 × 10) + (3 × 1)
Binary (base 2)
Two digits: 0 and 1. Each position is a power of 2.
1010 1101 = 128 + 32 + 8 + 4 + 1 = 173
Octal (base 8)
Eight digits: 0–7. Each position is a power of 8. Rarely used today but appears in Unix file permissions — chmod 755 sets permissions as three octal digits.
2 5 3 (octal) = (2 × 64) + (5 × 8) + (3 × 1) = 173 (decimal)
Hexadecimal (base 16)
Sixteen digits: 0–9 and A–F. Each position is a power of 16. Widely used throughout computing.
AD (hex) = (10 × 16) + (13 × 1) = 173 (decimal)
Why hexadecimal is so useful
One hex digit represents exactly 4 binary bits. Two hex digits represent exactly one byte (8 bits). This creates a compact, readable shorthand for binary data that's far easier to work with than raw binary strings.
1010 1101 (binary) = AD (hex) — dramatically more readable.
Common uses of hexadecimal:
- CSS colors:
#FF6B6B= red 255, green 107, blue 107 - Memory addresses:
0x7FFF5FBFF8A0 - Unicode code points: U+1F600 (😀)
- File signatures: The first few bytes identify a file's format (PNG starts with
89 50 4E 47) - Cryptographic hashes: SHA-256 outputs 64 hex characters (32 bytes)
Bits, bytes, and integer ranges
| Unit | Bits | Values representable |
|---|---|---|
| 1 nibble | 4 | 0–15 (0x0–0xF) |
| 1 byte | 8 | 0–255 (0x00–0xFF) |
| 2 bytes (uint16) | 16 | 0–65,535 |
| 4 bytes (uint32) | 32 | 0–4,294,967,295 |
| 8 bytes (uint64) | 64 | 0–18,446,744,073,709,551,615 |
Signed vs unsigned
A signed 8-bit integer uses the most significant bit as a sign bit, giving a range of −128 to 127. An unsigned 8-bit integer uses all 8 bits for magnitude, giving 0–255.
Bitwise operations
Operations that work directly on individual bits — extremely common in systems programming, embedded code, and cryptography.
| Operation | Symbol | Description | Example |
|---|---|---|---|
| AND | & |
1 only when both bits are 1 | Used for masking specific bits |
| OR | | |
1 when either bit is 1 | Used for setting specific bits |
| XOR | ^ |
1 when bits differ | Used for toggling bits |
| NOT | ~ |
Inverts all bits | Bitwise complement |
| Left shift | << |
Shifts bits left, fills with 0s | Equivalent to ×2 per shift |
| Right shift | >> |
Shifts bits right | Equivalent to ÷2 per shift |
Practical examples
// Check if bit 3 is set (bit masking)
value & (1 << 3)
// Set bit 3
value | (1 << 3)
// Clear bit 3
value & ~(1 << 3)
// Toggle bit 3
value ^ (1 << 3)
// Fast multiply by 8
value << 3
// Fast integer divide by 4
value >> 2
Text to binary
Every text character has a numeric code. ASCII defines codes 0–127 for English characters:
- 'A' = 65 =
0100 0001 - 'a' = 97 =
0110 0001 - '0' = 48 =
0011 0000 - Space = 32 =
0010 0000
Unicode extends ASCII to cover all world languages and emoji. UTF-8 encodes Unicode characters as 1–4 bytes, with ASCII characters unchanged (backward compatible).
"Hi" in binary: 01001000 01101001
How to convert numbers free
- Go to Binary Converter
- Select your input base (Binary, Octal, Decimal, or Hex)
- Type a value — all other bases update simultaneously
- Click individual bits in the interactive editor to toggle them
- Switch to Text mode to encode/decode ASCII strings
- Use the Bitwise tab to compute AND, OR, XOR, NOT, shift operations
- Check the Reference tab for common values (0xFF, 0x7F, etc.)