Skip to main content
FutureStack
Developer Tooling
•11 min read•Last Verified: 2026-12-03

Binary, Hex and Decimal Conversions Every Developer Should Know

Binary, hex and decimal are the three number systems developers actually meet every day — in colour codes, file permissions, bitwise flags, memory addresses and network masks. This guide shows how to convert between them by hand, the mistakes that bite, and when a converter earns its place.

Ali Gohar

Ali Gohar

Technical Contributor

Binary, Hex and Decimal Conversions Every Developer Should Know

Binary, Hex and Decimal Conversions Every Developer Should Know

You have probably read hexadecimal today without noticing. A colour in a stylesheet, a permission on a server, a memory address in a crash log — all of it is numbers written in a base other than ten. Binary, hexadecimal and decimal are three spellings of the same values, and moving between them is a small skill with an outsized payoff: strings that looked like noise start carrying information. This guide covers where each system shows up in daily work, how to convert between them by hand, and the mistakes that catch people out.

Three Systems, One Set of Numbers

Decimal is base 10: ten digits, and each position is worth ten times the one to its right. Binary is base 2 — only 0 and 1 — where each position doubles: 1, 2, 4, 8, 16, and so on. Hexadecimal is base 16, using 0–9 plus A–F for the values ten to fifteen.

Hex exists for one practical reason: one hex digit is exactly four binary digits (a nibble), so a byte — eight bits — is always exactly two hex digits. That tidy fit is why hex became the standard shorthand for binary data.

HexDecimalBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

For binary work, the other table worth memorising is the weight of each bit in a byte:

Bit position76543210
Weight1286432168421

Where You Meet Them Every Day

Colours in CSS and design tools

A CSS colour like #1E90FF is three hex bytes glued together: red, green, blue. Split it into pairs and convert each one. 1E is 30, 90 is 144, and FF is 255 — so the colour is rgb(30, 144, 255), the bright blue browsers call dodgerblue. Once you see the pairs, a colour stops being a magic string: raise the first pair and the colour gets redder, and FF in any position means that channel is at full strength.

File permissions

Run chmod 755 on a Unix-like system and you are writing binary in disguise. Each octal digit is a three-bit group where read is worth 4, write is worth 2 and execute is worth 1. So 7 (4+2+1, binary 111) means read, write, execute; 5 (4+1, binary 101) means read and execute. The mode 755 therefore reads as rwxr-xr-x: the owner can do everything, everyone else can read and run but not modify. The common file mode 644 is the same logic — owner read/write (6), the rest read-only (4).

Bash
chmod 755 deploy.sh    # rwxr-xr-x: owner can do everything
chmod 644 config.json  # rw-r--r--: owner read/write, others read-only

Bitwise flags

Many APIs pack options into a single number, one bit per option. Say read is 1, write is 2 and execute is 4. Combining read and execute with the OR operator gives 1 | 4 = 5, binary 101 — the two chosen bits are lit, the write bit is dark. Testing is the reverse: value & 2 asks whether the write bit is set. This is the same pattern behind permission bits, feature flags and hardware registers, and it only reads clearly if you picture the bits, not the decimal total.

JavaScript
const READ = 1, WRITE = 2, EXECUTE = 4;
const perms = READ | EXECUTE;              // 5, binary 101
const canWrite = (perms & WRITE) !== 0;    // false — the write bit is dark
const withWrite = perms | WRITE;           // 7, binary 111

Memory and debugging

Debuggers, hex editors and crash dumps speak hex because of the byte fit described above. An address like 0x7FFC2D40 is long, but each pair of digits is one byte, and values like 0xFF (255, the largest single byte) or 0x00 (an empty byte) are recognisable at a glance. In raw binary the same byte is 11111111 — correct, but slow to scan and easy to mistype.

Networking

A subnet mask such as 255.255.255.0 is binary wearing decimal clothes. Each 255 is eight 1 bits in a row (11111111), so the mask is twenty-four 1s followed by eight 0s — which is exactly what the /24 in an address like 192.168.1.0/24 is counting. MAC addresses go further and are written directly in hex: a full address has six pairs, such as 3C:7A:9F:41:2B:08, and each pair is one byte of the hardware address.

Characters and encodings

Text is numbers too. In ASCII, the letter A is 65 — 0x41 in hex, 01000001 in binary. UTF-8 keeps those same codes for plain English but uses extra bytes for everything else: é is stored as the two bytes C3 A9. That is why a mis-decoded file shows strange pairs of characters — the reader has split a multi-byte character into single bytes and looked each one up separately.

Converting by Hand

Binary to decimal: add the weights

Write the bit weights over the digits and add up the ones that sit under a 1. Take 11010110:

128 + 64 + 0 + 16 + 0 + 4 + 2 + 0 = 214

Only five additions, because the zeros contribute nothing. This is the fastest conversion to do mentally, and the one worth practising until it is automatic for single bytes.

Decimal to binary: subtract powers, or divide

For 45, work down through the powers of two. The largest power that fits is 32, leaving 13. Next is 8, leaving 5. Then 4, leaving 1. Then 1 itself. The powers used — 32, 8, 4, 1 — are bit positions, so 45 in binary is 101101.

The pencil-and-paper alternative is repeated division: divide by 2, note the remainder, repeat with the quotient until it reaches zero, then read the remainders from last to first. For 45 the remainders come out 1, 0, 1, 1, 0, 1 — reading them backwards gives the same 101101.

Binary and hex: group by four

This is the easiest conversion of all, because of the nibble fit. Split the binary into groups of four starting from the right, then translate each group using the table above. 10111110 splits into 1011 and 1110, which are B and E — so the value is 0xBE. Going the other way, expand each hex digit into four bits: 0xBE becomes 1011 1110. No arithmetic at all. For anything longer than a byte or two, though, the grouping and table lookups get slow and slip-prone, which is where a free binary, hex and decimal converter earns its keep — paste the string, read all the bases at once, and keep your attention on the problem you were actually solving.

Hex to decimal: multiply by sixteen

Hex positions are powers of sixteen, so work left to right: multiply by 16, add the next digit. For 0x2D: 2 × 16 = 32, plus D (13) gives 45 — the same 45 we converted to 101101 above, which is a good self-check. A three-digit example: 0x3E8 is 3 × 256 + 14 × 16 + 8 = 768 + 224 + 8 = 1000.

In code, the same conversions are one-liners — useful for checking your hand calculations:

JavaScript
parseInt('2D', 16);   // 45 — hex to decimal
(45).toString(2);     // '101101' — decimal to binary
(45).toString(16);    // '2d' — decimal to hex
parseInt('101101', 2); // 45 — binary to decimal

From the Field: Two Mistakes That Cost Real Time

Two mistakes from real projects show why this skill matters beyond exams. The first was a design token that lost a digit: a colour written as #1E90F instead of #1E90FF in a shared stylesheet. Browsers treat a five-digit hex colour as invalid, so the rule silently fell back to the inherited colour and a whole section shipped in the wrong shade. Nobody noticed for a week, because nothing errored — the value simply was not a colour. Reading hex as pairs would have caught it in seconds: a valid six-digit colour is always three pairs.

The second was a deploy script left world-writable after a rushed chmod 777 during a late-night fix. It worked fine until another process on the shared server overwrote the script, and the next deploy ran the wrong commands. The fix was not a better tool but a better habit: reading the permission digits as bits (7 is 111, full access for everyone) before typing them. Both bugs were cheap to prevent and expensive to find, and both came down to treating a number in another base as if it were decoration.

Mistakes That Bite

Grouping from the left. Binary-to-hex groups of four must start from the right. Group 1011110 from the left and you will invent a wrong leading digit; from the right it is 0101 1110 — 0x5E, the value 94.

Treating hex letters as decoration. A to F are numbers. 0x10 is sixteen, not ten, and an address ending in B is one higher than the same address ending in A.

Losing leading zeros. Inside a byte, 0x0A (ten) and 0xA0 (one hundred and sixty) are different values. When you expand hex to binary, every digit gets its full four bits, including the zeros.

Forgetting the signed question. 0xFF is 255 as an unsigned byte, but −1 when the byte is read as signed two's complement. The bits are identical; the interpretation is a choice the code makes, and mixing the two up produces bugs that look impossible until you check.

Pitfalls When Using Automated Converters

Converters are fast, but they have their own traps. Watch for these before trusting an output:

  • The 0x prefix. Some converters reject 0x2D as invalid input, while others read it fine. Strip the prefix, or use a tool that states it accepts it, before assuming the result is wrong.
  • The assumed input base. Typing 10 into a converter that defaults to hex gives 16, not ten. Always check which base the input field is set to.
  • Signed versus unsigned. A converter showing 255 for 0xFF is correct for an unsigned byte — but your code may read the same byte as −1. The tool cannot know which interpretation your program uses.
  • Dropped leading zeros. 0x0A pasted as A is still ten, but if you are comparing fixed-width values, pad the result back to full bytes before comparing.
  • No spot check. When the result feeds a permission, a mask or an address, convert one byte by hand first. A thirty-second check beats debugging a wrong value in production.

When a Converter Saves Time — and When It Doesn't

Hand conversion is worth learning for byte-sized values because it builds the picture behind permissions, masks and flags; you will read those faster for the rest of your career. But nobody should convert a 64-bit address, a long hash or a page of hex dump by hand — that is slow, error-prone, and the errors hide well. The honest split: convert small values yourself to stay fluent, use a tool for anything long or anything you cannot afford to get wrong, and spot-check the tool's output on one byte by hand when the stakes are high.

Quick Questions

Why not just use binary for everything? Length. A single byte is eight characters in binary and two in hex, and a 64-bit value is sixty-four characters. Hex keeps the exact bit structure visible at a quarter of the width.

Is 0x the same as #? No. The 0x prefix in most programming languages simply announces "hex follows". The # in CSS is colour syntax — the six digits after it are three hex bytes, as in the 1E90FF example above.

How do I read a long binary number quickly? Don't read it as decimal at all. Group it into fours from the right, translate each group to hex, and work with the short hex form — that is what it was for.


Ali Gohar is the founder of toolifyhub.tools, a free collection of browser-based tools for developers, students and creators.

Ali Gohar
Written & Verified byLast Verified: 2026-12-03

Ali Gohar

Technical Contributor

Founder of toolifyhub.tools — a free, privacy-first collection of online tools for developers, students and creators.

Author Attribution:Ali Gohar
Read all publications by Ali Gohar
Related Engineering Workbench

Free Client-Side AI & Systems Calculators

Size GPU KV-cache VRAM, estimate LLM token costs, audit JWTs, or generate Zod schemas with zero server uploads.

Explore Free Developer Tools
Next in Track • AI Engineering

What a Chrome Profile Checkpoint Actually Restores

A reproducible Chromium test for distinguishing persistent browser data, an unsubmitted form, and a copied profile’s later writes.

Read Next Investigation
Interactive Practice • Free No Login

Test this topic live in Fusta AI Code Canvas

Ask follow-up questions or generate a working React, TypeScript, or Python example based on “Binary, Hex and Decimal Conversions Every Developer Should Know”.

Deliberations (0)

Moderated • Anti-Spam & Link Safety Active

Contribute your perspective

Loading discussion thread...