Binary/Hex/Octal Converter
Convert numbers between binary, hexadecimal, octal, and decimal bases.
The Formula
N = Σ(digit × 2ⁱ) right to left
Decimal → Binary:
Divide by 2, record remainders bottom to top
= 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 8 + 4 + 0 + 1
= 13
Decimal 25 → Binary: 11001
The Four Number Bases
Decimal (base 10) is the everyday number system using digits 0–9. It is what humans use naturally, likely because we have ten fingers. Binary (base 2) uses only digits 0 and 1 and is the language of computers — every transistor, bit of memory, and logic gate operates in binary. Octal (base 8) uses digits 0–7 and was once common in computing; it is still used in Unix/Linux file permissions (where each digit represents three binary bits). Hexadecimal (base 16) uses digits 0–9 and letters A–F and is widely used by programmers because one hex digit neatly represents exactly four binary bits, making it a compact representation of binary data.
How to Convert Between Bases
To convert from any base to decimal, multiply each digit by its positional value (the base raised to the position power, starting from 0 on the right) and sum the results. Binary 1011 in decimal: (1×2³) + (0×2²) + (1×2¹) + (1×2⁰) = 8 + 0 + 2 + 1 = 11. To convert from decimal to another base, repeatedly divide by the target base and collect the remainders reading upward. To convert between non-decimal bases, the easiest path is often through decimal as an intermediate step.
Practical Uses
Binary is the native language of all digital computing — understanding it helps with bit manipulation, networking, and low-level programming. Hex appears constantly in web development (HTML color codes like #FF5733), programming (memory addresses, byte values), and debugging. Octal is used for Unix file permissions: chmod 755 sets owner-read/write/execute (7 = 111 in binary) and group/others-read/execute (5 = 101 in binary).
Frequently Asked Questions
Why do computers use binary?
Binary maps directly to the physical reality of digital circuits, where a transistor can be in one of two states: on (1) or off (0). Building reliable circuits around just two states is vastly simpler and more noise-resistant than building them around ten states (decimal). All computer data — text, images, audio, video — is ultimately stored and processed as binary patterns.
What is hexadecimal used for in programming?
Hex is used to represent binary data compactly. Since one hex digit represents exactly four binary bits, a byte (8 bits) is always exactly two hex digits — making hex far more readable than raw binary. Uses include memory addresses (0x7FFE3A), color codes in web development (#FF5733), byte values in networking protocols, and debugging output in development tools.
How do I convert binary to decimal?
Write out the binary number and assign positional values starting from the right: the rightmost bit is 2⁰=1, next is 2¹=2, then 2²=4, 2³=8, and so on. For each bit that is 1, add its positional value. Binary 10110: (1×16) + (0×8) + (1×4) + (1×2) + (0×1) = 16 + 0 + 4 + 2 + 0 = 22.
What does 0x mean before a number?
The 0x prefix is a programming convention indicating the following number is in hexadecimal. So 0xFF means hex FF, which equals decimal 255. Similarly, 0b prefixes binary numbers (0b1010 = decimal 10) and 0 (just a leading zero) prefixes octal in many programming languages (017 = decimal 15). These prefixes prevent ambiguity when multiple bases appear in the same code.
How are Unix file permissions related to octal?
Unix permissions are displayed as three groups (owner, group, others), each with three bits: read (4), write (2), execute (1). Add the values of the permissions you want: rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, r-- = 4+0+0 = 4. A permission string of 755 means owner has full permissions (7), group and others can read and execute (5). Each digit is one octal number representing three binary permission bits.