Technical
Number Base Conversion: Developer Guide
personWritten by Magnus Silverstream
•calendar_todayNovember 8, 2025
•schedule7 min read
Every number you see on screen is ultimately represented as binary in your computer's memory. Yet we use decimal for human interfaces, hexadecimal for colors and memory addresses, and octal for file permissions. Understanding number bases isn't just academic - it's essential for debugging, working with low-level code, and understanding how computers actually work. This guide explains the most important number bases and how to convert between them.
Understanding number bases
A number base (or radix) defines how many unique digits are used to represent numbers.
Common bases:
• Binary (Base 2): 0, 1
• Octal (Base 8): 0-7
• Decimal (Base 10): 0-9
• Hexadecimal (Base 16): 0-9, A-F
The position of each digit determines its value:
• In decimal 253: 2×100 + 5×10 + 3×1
• In binary 11111101: 128+64+32+16+8+4+0+1 = 253
• In hex FD: 15×16 + 13×1 = 253
Why different bases exist:
• Binary: How computers actually store data
• Octal: Compact binary (3 bits per digit), Unix permissions
• Decimal: Human-friendly, our natural counting system
• Hexadecimal: Compact binary (4 bits per digit), colors, memory
Binary: the computer's language
Everything in a computer is ultimately binary - ones and zeros representing electrical states (on/off).
Binary basics:
• Each digit is called a bit
• 8 bits = 1 byte
• Maximum byte value: 11111111 = 255
Common binary patterns:
• 00000000 = 0
• 00000001 = 1
• 00001010 = 10
• 01100100 = 100
• 11111111 = 255
Why developers need binary:
• Understanding bitwise operations (AND, OR, XOR)
• Working with hardware and embedded systems
• Network protocols and data structures
• Debugging memory issues
• Compression algorithms
Binary prefixes:
• In code: 0b prefix (0b1010 = 10)
• Bit manipulation is incredibly fast
• Powers of 2 are clean binary numbers
Hexadecimal: the developer's favorite
Hexadecimal (base 16) is everywhere in programming because it maps perfectly to binary - each hex digit represents exactly 4 bits.
Hex digits: 0-9, then A=10, B=11, C=12, D=13, E=14, F=15
Common uses:
Colors (RGB)
• #FF0000 = Red (255, 0, 0)
• #00FF00 = Green (0, 255, 0)
• #FFFFFF = White (255, 255, 255)
Memory addresses
• 0x7FFE0000 (stack pointer)
• Error messages often show hex addresses
Character codes
• ASCII 'A' = 0x41 = 65
• Unicode uses hex extensively
Binary data
• Byte values: 0x00 to 0xFF
• SHA-256 hashes displayed in hex
Hex prefixes:
• 0x in most languages (0xFF)
• # for CSS colors (#FF0000)
• \x for escape sequences (\x41)
Octal: Unix permissions and beyond
Octal (base 8) is less common but crucial for Unix/Linux file permissions.
Octal digits: 0-7
File permissions explained:
• Read (r) = 4
• Write (w) = 2
• Execute (x) = 1
Permission combinations:
• 7 (rwx) = 4+2+1 = read+write+execute
• 6 (rw-) = 4+2 = read+write
• 5 (r-x) = 4+1 = read+execute
• 4 (r--) = read only
Common permission sets:
• 755 = rwxr-xr-x (owner full, others read/execute)
• 644 = rw-r--r-- (owner read/write, others read)
• 777 = rwxrwxrwx (full access to everyone - dangerous!)
Other octal uses:
• C escape sequences (\077 = ?)
• Some legacy systems
• Compact representation of 3-bit groups
Octal prefix in code: Leading zero (0755)
Converting between bases
Manual conversion methods:
Decimal to binary:
1. Divide by 2, note remainder
2. Repeat until quotient is 0
3. Read remainders bottom-to-top
Example: 13 to binary
13÷2 = 6 r1
6÷2 = 3 r0
3÷2 = 1 r1
1÷2 = 0 r1
Result: 1101
Binary to hex (easy!):
1. Group binary digits in 4s from right
2. Convert each group to hex digit
Example: 11111101
1111 1101
F D
Result: FD
Hex to binary:
1. Convert each hex digit to 4 binary digits
Example: 2A
2 = 0010
A = 1010
Result: 00101010
Quick mental math:
Powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256...
Programming with different bases
Most languages support multiple bases natively:
JavaScript:
let binary = 0b1010; // 10
let octal = 0o12; // 10
let hex = 0x0A; // 10
num.toString(2); // to binary string
parseInt('1010', 2); // from binary string
Python:
binary = 0b1010 # 10
octal = 0o12 # 10
hex_num = 0x0A # 10
bin(10) # '0b1010'
oct(10) # '0o12'
hex(10) # '0xa'
int('1010', 2) # 10
Common operations:
• Bitwise AND: a & b
• Bitwise OR: a | b
• Bitwise XOR: a ^ b
• Left shift: a << n (multiply by 2^n)
• Right shift: a >> n (divide by 2^n)
Practical tip: When debugging, console.log with .toString(16) to see hex values.
Conclusion
Understanding number bases is fundamental to programming. Binary is how computers think, hexadecimal is how developers communicate binary compactly, octal handles Unix permissions, and decimal is for human interfaces. The key insight is that these are all different ways of representing the same values - 255, 0xFF, 0b11111111, and 0377 are identical numbers. Use our base converter tool to quickly convert between number systems and explore how different bases relate to each other.
Frequently Asked Questions
Hexadecimal is more compact and readable while still mapping directly to binary. Each hex digit represents exactly 4 bits, so a byte (8 bits) is just 2 hex digits. Writing FF is much easier than 11111111, and both represent 255.