Number Systems for Developers: Binary, Octal, Decimal, and Hexadecimal
Why Number Systems Matter
Every developer encounters different number systems. Binary for bitwise operations, hexadecimal for colors and memory addresses, octal for file permissions. Understanding these systems makes you a more effective programmer.
Decimal (Base 10)
The system we use daily. It uses 10 digits (0-9) and each position represents a power of 10.
456 = 4×10² + 5×10¹ + 6×10⁰
= 400 + 50 + 6
Binary (Base 2)
The language of computers. Uses only 2 digits (0 and 1). Each position represents a power of 2.
1101 = 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 8 + 4 + 0 + 1
= 13 (decimal)
Binary in Programming
Binary is essential for:
- Bitwise operations:
&,|,^,~,<<,>> - Flags and permissions: Each bit represents a true/false flag
- Network masks:
255.255.255.0=11111111.11111111.11111111.00000000
// Bitwise AND
0b1100 & 0b1010 // = 0b1000 (8)
// Check if a flag is set
const flags = 0b1010;
const isAdmin = (flags & 0b0010) !== 0; // true
Octal (Base 8)
Uses 8 digits (0-7). Each position represents a power of 8.
157 = 1×8² + 5×8¹ + 7×8⁰
= 64 + 40 + 7
= 111 (decimal)
Octal in Practice: Unix File Permissions
The chmod command uses octal to represent file permissions:
chmod 755 file.txt
7 = rwx (read + write + execute)
5 = r-x (read + execute)
5 = r-x (read + execute)
Each digit is 3 bits: r=4, w=2, x=1
Use our Chmod Calculator to calculate file permissions.
Hexadecimal (Base 16)
Uses 16 digits: 0-9 and A-F (where A=10, B=11, ... F=15). Each position represents a power of 16.
0x1A3 = 1×16² + 10×16¹ + 3×16⁰
= 256 + 160 + 3
= 419 (decimal)
Hexadecimal in Practice
Colors in CSS:
color: #FF5733; /* Red=FF(255), Green=57(87), Blue=33(51) */
Memory addresses:
0x7FFE0012 /* Pointer to memory location */
Unicode characters:
U+00E9 = é (Latin small letter e with acute)
MAC addresses:
00:1A:2B:3C:4D:5E
Try These Conversion Tools
- Base Converter: Convert between binary, octal, decimal, and hex
- Binary to Decimal: Convert binary numbers to decimal
- Hex to Decimal: Convert hexadecimal to decimal
- Binary Text Converter: Convert text to/from binary representation
Quick Conversion Table
| Decimal | Binary | Octal | Hex | |---------|--------|-------|-----| | 0 | 0000 | 0 | 0 | | 5 | 0101 | 5 | 5 | | 10 | 1010 | 12 | A | | 15 | 1111 | 17 | F | | 255 | 11111111 | 377 | FF | | 1024 | 10000000000 | 2000 | 400 |
Converting Between Bases
Decimal to Binary
Divide by 2 repeatedly, record remainders:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read remainders bottom-up: 1101
Binary to Hexadecimal
Group bits in sets of 4, convert each group:
1101 0110
D 6
= 0xD6
Hex to Decimal
Multiply each digit by its position power of 16:
0x2F = 2×16 + 15 = 32 + 15 = 47
Tools for Number Conversions
- Base Converter: Convert between any bases
- Binary to Decimal: Quick binary conversion
- Hex to Decimal: Hex to decimal converter
- Binary Text Converter: Convert text characters to binary
- Hex Encoder: Encode text as hex strings
- ASCII Table: Reference ASCII character codes in all bases
- Chmod Calculator: Calculate Unix file permissions
Conclusion
Number systems are fundamental to programming. Use our Base Converter to quickly convert between binary, octal, decimal, and hexadecimal.
Try our free developer tools
All tools run in your browser with zero data uploads.