Number Systems
Binary, octal, decimal and hexadecimal — and converting between them.
Beginner
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| 10 | 1010 | A |
| 15 | 1111 | F |
| 255 | 1111 1111 | FF |
To convert decimal to binary, divide by 2 repeatedly and read the remainders bottom-up. Each hex digit is exactly 4 bits, so hex is a compact way to write binary: 0x3F = 0011 1111.
In code: 0b1010 (binary), 0x1F (hex), 017 (octal in C — a common surprise!).
Sub-topics (2)
Binary Arithmetic and Two's Complement
Add binary numbers and represent negative integers with two's complement.
Easy♥ 0🔖 0💬 0
BCD and Gray Code
Binary-coded decimal stores each decimal digit in 4 bits; Gray code changes only one bit between consecutive values.
Easy♥ 0🔖 0💬 0
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.