Article — Binary Converter
Binary converter: decimal, binary, octal, and hexadecimal in one view
A binary converter switches a number between binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16). The four bases are interchangeable representations of the same value. 42 in decimal is 101010 in binary, 52 in octal, and 0x2A in hex — all the same number.
Binary is the native language of computers. Every byte of memory, every CPU instruction, and every network packet is a sequence of bits. Hex is the compact, human-readable form of binary because each hex digit maps to exactly 4 bits. Decimal is the form humans naturally read. Conversion between all four is a daily task in programming, networking, and digital electronics.
What a binary converter does
The converter takes a single value entered in one base and shows the equivalent representation in the other three bases. Internally it parses the input as a BigInt (so arbitrarily large numbers work) and then formats it back to each target base. The conversions are exact: there is no rounding or precision loss, because integer bases are an arithmetic property of the number itself.
Each base uses a different alphabet of digits. Binary has just 0 and 1. Octal uses 0-7. Decimal uses 0-9. Hex uses 0-9 plus A-F for the values 10-15. The converter validates input against the chosen base — entering "8" with octal selected will flag an error, since 8 is not a valid octal digit.
Gottfried Leibniz published the first systematic description of binary arithmetic in 1703 — about 240 years before the first electronic computer. He saw it as elegant proof that all numbers and logic could be reduced to two states. Today every chip on Earth runs on his idea.
History of the binary number system
Ancient Egyptian and Indian mathematicians used binary-like systems for various calculations, but Gottfried Wilhelm Leibniz in 1703 wrote the first formal exposition of binary arithmetic in "Explication de l'Arithmétique Binaire." He suggested it as the simplest possible number system: everything is 0 or 1.
Binary remained an academic curiosity until George Boole's algebra (1847) showed how logic operations (AND, OR, NOT) could be formalised on binary values. Claude Shannon's 1937 master's thesis demonstrated that electronic switches could implement Boolean logic. The combination — binary representation plus Boolean logic — became the architecture of every digital computer built since the 1940s.
0 = 0₂ = 0₈ = 0₁₆10 = 1010₂ = 12₈ = A₁₆16 = 10000₂ = 20₈ = 10₁₆42 = 101010₂ = 52₈ = 2A₁₆255 = 11111111₂ = 377₈ = FF₁₆65535 = 16 bits all set = FFFF₁₆Converting binary to decimal
Read the binary digits from right to left. The rightmost bit is multiplied by 2⁰ = 1, the next by 2¹ = 2, then 2² = 4, 2³ = 8, and so on. Sum the products. 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 11.
To go from decimal to binary, divide by 2 and collect the remainders. 42 ÷ 2 = 21 remainder 0. 21 ÷ 2 = 10 remainder 1. 10 ÷ 2 = 5 remainder 0. Continue until the quotient is 0, then read the remainders bottom-up: 101010. The converter does both directions instantly with arbitrary-precision integers.
Converting binary to hexadecimal
Binary and hex are directly related: 4 bits = 1 hex digit. Group binary bits in fours from the right, then map each group to a hex character. 11011001 splits into 1101 1001, which maps to D9. Going the other way, expand each hex digit into 4 bits: 0xFF = 1111 1111. No decimal arithmetic is needed for the conversion.
This compact mapping is why hex dominates computer documentation. A 32-bit value like 0x12345678 is far easier to read than the 32-character binary 00010010001101000101011001111000. Memory addresses, colour codes, MAC addresses, and instruction encodings all use hex for this reason.
Bit widths, bytes, and signed numbers
Hardware imposes natural bit boundaries. The 8-bit byte holds values 0 to 255 (unsigned) or -128 to 127 (signed two's complement). A 16-bit short holds 0 to 65,535 unsigned. A 32-bit integer (the size of an IPv4 address) holds 0 to 4,294,967,295. A 64-bit integer reaches about 1.8 × 10¹⁹.
- 1 bit = 0 or 1
- 1 nibble = 4 bits = 0 to 15 = 1 hex digit
- 1 byte = 8 bits = 0 to 255 = 2 hex digits
- 1 short = 16 bits = 0 to 65,535
- 1 int (32-bit) = 0 to 4,294,967,295
- 1 long (64-bit) ≈ 0 to 1.84 × 10¹⁹
- IPv4 address = 32 bits = 4 bytes
- IPv6 address = 128 bits = 16 bytes
Where binary is used in computing
Every computer instruction is a binary pattern. CPU registers, memory cells, and disk sectors all store bits. Networking protocols transmit binary frames; the TCP and IP headers are bit-level layouts. Image files store pixel colours as bytes (each colour channel is 8 bits, 0-255). Crypto algorithms operate on bit patterns directly via XOR and other bitwise operations.
Programmers see decimals when reading display values, hex when debugging memory, and binary when manipulating bit masks. Switching between the three is one of the most common tasks in low-level programming. Higher-level languages hide most of it, but kernels, drivers, embedded firmware, and crypto code work in raw bits all day.
Common binary-conversion mistakes
Three mistakes recur. First, miscounting bits. A 32-bit integer has 32 bits, not 32 bytes. A 32-bit number written in hex needs 8 hex digits (32 ÷ 4), not 32. Always check digit count when reading binary or hex literals. Second, mixing signed and unsigned interpretations. The bit pattern 0xFF is 255 unsigned but -1 in 8-bit signed two's complement. Computer architectures need to know which interpretation applies. Third, confusing prefix conventions. 0x2A is hex 42, 0b101010 is binary 42, 0o52 is octal 42 — the prefix matters. A bare "101010" could mean any of decimal, binary, or octal depending on context.
In modern code, use base prefixes: 0b for binary, 0o for octal, 0x for hex, and no prefix for decimal. JavaScript, Python, Rust, and most other languages recognise all four. This eliminates ambiguity when reading literals in source code.
The bit pattern 0xFFFFFFFF can mean two very different numbers. As an unsigned 32-bit integer it is 4,294,967,295. As a signed 32-bit integer in two's complement it is -1. The pattern is identical; only the type interpretation differs. C, Rust, and other low-level languages distinguish; JavaScript and Python infer from context.