Computers store everything as binary — sequences of ones and zeros representing on/off electrical states. But binary is cumbersome for humans to read and write. A 32-bit integer requires 32 binary digits. This is why developers use hexadecimal as a compact binary shorthand and occasionally octal for Unix file permissions and other legacy contexts. Understanding these number systems removes the mystery from memory addresses, color codes, file permissions, and bit manipulation operations.
How Number Bases Work
A number base (or radix) defines how many unique digits a number system uses. Decimal (base 10) uses digits 0–9. Binary (base 2) uses only 0 and 1. Octal (base 8) uses 0–7. Hexadecimal (base 16) uses 0–9 and then A–F to represent values 10–15. Each digit position represents a power of the base: in decimal, 123 means 1×100 + 2×10 + 3×1. In binary, 1101 means 1×8 + 1×4 + 0×2 + 1×1 = 13.
The key insight is that any integer can be exactly represented in any base — only the notation changes. The number thirteen is 13 in decimal, 1101 in binary, 15 in octal, and D in hexadecimal. These are all the same value. The base you choose is a representation choice that affects readability and convenience for different tasks.
Conversion between bases follows a consistent algorithm. To convert from decimal to another base, repeatedly divide by the target base and record the remainders in reverse order. To convert from binary to any other base that is a power of 2 (like 8 or 16), group the binary digits into chunks of 3 (for octal) or 4 (for hex) and convert each chunk directly.
Binary: The Language of Hardware
Binary is the native language of digital circuits. A bit is a single binary digit. A byte is 8 bits, capable of representing 256 values (0–255 in decimal, 00–FF in hex). Understanding bit patterns is essential for working with binary file formats, network protocols, hardware registers, and bitwise operations in code.
Bitwise operators (AND, OR, XOR, NOT, shift left, shift right) manipulate individual bits. These operations are used constantly in systems programming, cryptography, and performance-sensitive code. A left shift by one position (x << 1) is equivalent to multiplying by 2. A bitwise AND with a mask (x & 0xFF) extracts the lowest 8 bits. Recognizing these patterns in code requires thinking in binary.
Two's complement is the standard representation for signed integers in binary. Positive numbers are represented normally. For negative numbers, flip all bits and add 1: the 8-bit representation of -1 is 11111111. This encoding makes subtraction work correctly using the same circuit as addition, which is why CPUs implement subtraction as addition of the two's complement.
Hexadecimal: The Developer's Shorthand
Hex is beloved by developers because each hex digit represents exactly 4 bits (a nibble). This means one byte is always exactly two hex digits: 0xFF = 255 = 11111111 in binary. This clean mapping makes hex a compact, lossless shorthand for binary values. A 32-bit memory address that would require 32 binary digits is expressed in 8 hex digits.
Hex appears constantly in development contexts: HTML/CSS color codes (#FF5733), memory addresses (0x7FFF5FBFF8B8), Unicode code points (U+1F600), byte-level representations in debuggers and hex editors, and SHA-256 hash outputs (64 hex characters = 256 bits). Recognizing that these are all just numbers in base 16 demystifies much of what looks like random strings.
In most programming languages, hex literals are prefixed with 0x: 0xFF is 255, 0x1A is 26. Some languages also support binary literals with 0b prefix (0b1101 = 13) and octal with 0o prefix (0o17 = 15). Mixing literal bases in a single expression is valid — 0xFF + 10 + 0b1010 is a legal expression that evaluates to 271.
Octal: File Permissions and Legacy Systems
Octal was commonly used in early computing systems because early hardware used 6-bit bytes that divided evenly into two 3-bit octal digits. Today, octal's main remaining use is Unix/Linux file permissions. A permission string like chmod 755 uses three octal digits, each representing three bits for owner, group, and others.
Each octal permission digit is the sum of read (4), write (2), and execute (1) values. chmod 755 sets the owner to rwx (4+2+1=7), group to r-x (4+0+1=5), and others to r-x (5). This encoding maps directly to a 9-bit binary value: 111 101 101. Understanding the octal-to-binary relationship makes permission strings immediately readable rather than requiring memorization.
Outside of file permissions, octal appears in some legacy protocols and older file formats. Modern protocols overwhelmingly use hexadecimal when binary shorthand is needed. If you encounter 0o or an octal literal in code, it is usually file permissions or a compatibility interface with a POSIX system call.
Binary, hex, and octal are not separate subjects — they are three lenses on the same underlying number. Fluency with these representations unlocks a clearer mental model of how data is stored and manipulated at the hardware level. When you see a hex color, a memory address, or a file permission, you are reading a number in a different base. A number base converter eliminates the arithmetic overhead of manual conversion, letting you focus on the logic of what the number means rather than the mechanics of translating it.