August 30, 2026 · 7 min read · by Quanta Calculator

Binary and Hex: Number Bases Programmers Actually Use

How place value turns binary 10110100 into 180 and 0xB4, plus a complete hex-to-binary chart and the grouping mistake that silently doubles a conversion

Minimalist geometric illustration of binary ones and zeros, hexadecimal digits and doubling place-value blocks in warm amber tones

Binary to decimal is place value and nothing else. The decimal string 180 unpacks as 1×100 + 8×10 + 0×1, because every decimal column is worth ten times its right-hand neighbor. Binary keeps that rule and swaps the multiplier for two, so its columns are worth 1, 2, 4, 8, 16, 32, 64 and 128, counting from the right. Take the byte 10110100. Write each bit beneath its weight and keep the columns holding a 1: the 128, the 32, the 16 and the 4. Add them: 128 + 32 + 16 + 4 = 180. That is the complete conversion: each bit says whether its power of two is in the number, and the value is the sum of the yeses.

If writing out weights feels fiddly, there is a route with no powers in it: start at zero and, for each bit taken left to right, double the running total and add the bit. On 10110100 the total climbs 1, 2, 5, 11, 22, 45, 90, 180. This double-and-add recurrence is what the binary converter executes internally, in exact digit-by-digit arithmetic rather than floating point — which is why it round-trips integers far past 9,007,199,254,740,991, the point where JavaScript's ordinary number type starts silently rounding.

One integer, several spellings

The idea that unlocks everything downstream: a base is a spelling system, not a kind of number. 180, 10110100 and B4 are three spellings of one integer, and programmers mark which spelling they mean with the base prefixes RFC 7373 standardizes — 0b10110100 for binary, 0xB4 for hexadecimal. So the identity 0b10110100 = 0xB4 = 180 is not three facts to check but one. Every positional system obeys the same rule:

value = Σ digit × base^position — positions counted from 0 at the rightmost digit

Octal — base 8, prefix 0o — obeys it too: 0o264 means 2×64 + 6×8 + 4×1 = 128 + 48 + 4 = 180 once more. The integer never changed; only its alphabet did.

Turning 180 back into bits

Converting away from decimal runs the machinery in reverse: divide by the target base, keep the remainder, repeat on the quotient until it reaches zero.

Step Quotient Remainder
180 ÷ 2 90 0
90 ÷ 2 45 0
45 ÷ 2 22 1
22 ÷ 2 11 0
11 ÷ 2 5 1
5 ÷ 2 2 1
2 ÷ 2 1 0
1 ÷ 2 0 1

Read the remainder column from the bottom up: 10110100. The direction matters: the first remainder answers the ones column, the rightmost digit, so reading top-down hands you the reversed string. Aim the same procedure at base 16 and it finishes in two steps: 180 ÷ 16 = 11 remainder 4, then 11 ÷ 16 = 0 remainder 11. Eleven is written B in hexadecimal, so the collected remainders reverse into B4.

The hex-to-binary chart

Hexadecimal and binary move in lockstep because 16 = 2⁴: one hex digit always corresponds to exactly four bits. NIST IR 8354 documents that correspondence, and RFC 4648 §8 fixes the alphabet: A through F stand for ten through fifteen. The full mapping is small enough to memorize:

Hex Binary Decimal Hex Binary Decimal
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 A 1010 10
3 0011 3 B 1011 11
4 0100 4 C 1100 12
5 0101 5 D 1101 13
6 0110 6 E 1110 14
7 0111 7 F 1111 15

With the chart in hand, binary-to-hex is transcription rather than arithmetic. Split the bits into groups of four starting from the right: 10110100 becomes 1011 and 0100. The chart maps 1011 to B and 0100 to 4, so 0xB4 falls out directly — agreeing with the two divisions above, which is the cross-check the chart exists to provide. Hex to binary is the same move backwards: expand each digit into its four-bit pattern. Octal plays the identical trick in threes, since 8 = 2³ — grouped as 10 110 100, the byte reads off as 264.

One rule deserves bold type: group from the right, and pad only the leftmost group. Getting it backwards is the classic silent error — more on that below.

Why hex earns its keep

A byte is eight bits, which allows 2⁸ = 256 distinct patterns — the values 0 through 255 — and eight bits is exactly two hex digits: the all-ones byte 11111111 tops out at 0xFF, which is 15×16 + 15 = 255. Two symbols per byte, with no carrying across the pair boundary, is the entire sales pitch: a 32-bit dump becomes eight hex characters, and any single byte decodes in isolation.

IPv4 addressing shows the payoff. RFC 791 defines an address as one 32-bit integer — the dots in 192.168.1.1 are display formatting, not structure the protocol sees. Because each dotted number is a byte, each converts to hex independently: 192 is 0xC0, 168 is 0xA8, and each 1 is 0x01, so the whole address is 0xC0A80101, the form you meet in a packet capture. Written as one plain decimal integer it is 3,232,235,777, the form a database column or a GeoIP range table stores. And written out as 32 raw bits, it is the only view in which a subnet mask's cut-off point is visible. The IP address converter moves among all of those spellings in both directions, plus the octal, reverse-DNS and IPv6-mapped forms carried by the same 32 bits.

Four mistakes that survive a quick glance

Reading the weights in the wrong direction. Weights grow right to left, but text reads left to right, and under time pressure the two swap. Assign ascending weights from the left of 10110100 and you get 1 + 4 + 8 + 32 = 45 — a plausible-looking answer that is actually the value of the byte's mirror image, 00101101.

Grouping nibbles from the left. Take the seven-bit string 1100100, which is 64 + 32 + 4 = 100. Grouped correctly from the right it is 110 0100; pad the left group to give 0110 0100, and the chart reads 0x64 = 6×16 + 4 = 100. Group from the left instead — 1100 100 — and pad the ragged group on the right to 1100 1000, and you will read 0xC8 = 12×16 + 8 = 200. Exactly double. Every zero appended on the right multiplies the value by two, while zeros prepended on the left cost nothing; when a hand conversion comes out at exactly twice or half a tool's answer, this is why.

Treating width as value. 0xB4, 0x00B4 and 0x000000B4 are one integer. Fixed-width fields in file formats and registers pad values with leading zeros, but the padding belongs to the field, not the number — which is why the converter strips insignificant leading zeros from its results and reports significant digit counts separately: 180 occupies eight binary digits and two hex digits, whatever its container's width.

Assuming the bits alone tell you the value. The byte 11111111 means 255 as an unsigned integer and −1 as a signed eight-bit two's-complement value; nothing in the digits announces which reading applies — only declared word width and signedness do. This guide and the converter treat bit strings as non-negative integers and say so, because guessing an interpretation is how wrong values get written down with full confidence.

Make it automatic

Fluency with bases is a practice effect, not a talent, and the fastest drill uses constants you already trust: 255 from subnet masks, 127 from localhost, 80 and 443 from port numbers. Spell each one in binary and hex by hand, then let a converter grade the work — knowing roughly where the answer should land is what turns a wrong digit into a lesson instead of a shrug. A week of that and the chart above stops being a chart; 1011 simply reads as B.

The last thing worth internalizing is scope. Both tools in this guide read digits as a single non-negative integer and stop there. A signed machine word, a floating-point layout or an address with a /24 attached carries structure the bare digits never announce, and each belongs to a purpose-built decoder — the full calculator index groups those neighbors under conversion and tech. Corrections to this article, from a wrong digit to a misread standard, go through the contact page.

Sources

More guides