๐ข Number Bases: A Programmer's Survival Guide
Binary, octal, decimal, hexadecimal โ and how to convert between them
Four Number Systems
| Base | Radix | Symbols | Use |
|---|---|---|---|
| Binary | 2 | 0, 1 | CPU, bitwise ops |
| Octal | 8 | 0โ7 | Unix permissions (chmod 755) |
| Decimal | 10 | 0โ9 | Everyday use |
| Hexadecimal | 16 | 0โ9, AโF | Colors, hashes, memory addresses |
255 decimal = binary
11111111 = octal 377 = hex FF
One-Line Conversion
// JavaScript โ any base to any base
parseInt('FF', 16).toString(2) // '11111111'
parseInt('11111111', 2).toString(10) // '255'
// Python
int('FF', 16) // 255
hex(255) // '0xff'
bin(255) // '0b11111111'
// Shell
echo "ibase=16; FF" | bc // 255
FAQ
Q: Why binary?
Transistors have two states โ on/off. Binary maps directly to hardware.
Q: Hex AโF?
A=10, B=11, C=12, D=13, E=14, F=15.
๐ Related: SHA256 Hash โ ยท Color Converter โ