All Tools View Categories Blog About Contact Privacy

Binary, Hex & Decimal Explained: A Complete Guide to Number Systems

Binary, Hex & Decimal Explained: A Complete Guide to Number Systems

10 decimal is 1010 in binary, A in hex, and 12 in octal — same value, four writings. This complete guide explains binary (base 2), decimal (base 10), hex (base 16) and octal (base 8): place value, how to convert by dividing or multiplying, why hex compacts 11111111₂ to FF₁₆, and real uses — #FF5733 colors, 0xFF bytes, and chmod 755 — with a quick table.

TL;DR — Binary, Hex & Decimal:
  • What: Decimal base 10 digits 0-9, Binary base 2 digits 0-1, Hex base 16 digits 0-9 + A-F (10-15), Octal base 8 digits 0-7 — all positional (d × base^position). 10₁₀ = 1010₂ = A₁₆ = 12₈.
  • Why hex: 1 hex digit = 4 bits, so 8-bit byte 11111111₂ → FF₁₆ (2 chars vs 8 bits) — compact, per hex on Wikipedia.
  • Place: 1010₂ = 1×8 +0×4 +1×2 +0×1 =10; 1A₁₆ =1×16+10=26; FF₁₆=255.
  • Convert: Decimal → Binary divide by 2 and read remainders up (10 →1010₂). Use our binary converter for any base; Decimal → Hex divide by 16 via our convert decimal to hex; Decimal → Octal divide by 8 via our convert decimal to octal.
  • Prefixes: Programmers write 0b1010 binary, 0xA hex, 0o12 octal, plain 10 decimal; subscript 1010₂ in text.

What Are Number Systems — Base 10, 2, 16, and 8

A number system is just how many distinct digits you have before you carry: base 10 has 0-9, base 2 has 0-1, base 16 has 0-9 plus A-F for 10-15, base 8 has 0-7. All are positional — each digit's value is digit × base^position with position 0 on the right.

We use decimal because of 10 fingers; computers use binary because transistor is on/off; hex compacts binary (4 bits → 1 hex) for humans reading bytes; octal fits 3 bits → legacy Unix permissions 755.

Number systems base 10 decimal base2 binary base16 hex base8 octal digits

Same value four ways (10 decimal): 10₁₀ = 1010₂ = A₁₆ = 12₈ — subscript shows base, prefix shows in code. See positional notation and MDN numeric literals for 0b/0x/0o.

Digits per Base

BaseDigitsPlace powersExample
10 Decimal0-910⁰=1, 10¹=10, 10²=1002024₁₀
2 Binary0,11,2,4,8,16...1010₂ =10
16 Hex0-9,A-F (A=10)1,16,256...A₁₆ =10, FF=255
8 Octal0-71,8,64...12₈=10

Place Value — Why 1010₂ = 8 + 2 = 10

Positions right-to-left are base^0, base^1, base^2...:

Decimal 2024 = 2×10³ + 0×10² + 2×10¹ + 4×10⁰ = 2000+0+20+4
Binary  1010₂ = 1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 8 + 0 + 2 + 0 = 10
Hex     1A₁₆ = 1×16¹ + 10×16⁰ = 16 + 10 = 26
FF₁₆ = 15×16 +15 = 255 (max byte)
Place value binary 1010 equals 8 plus 2 hex 1A equals 26

Hex = 4 bits: binary 1010 is one hex digit A because 2^4=16 — one hex covers 0000(0) to 1111(15=F). So byte 11111111₂ splits as 1111 1111F FFF₁₆ =255, two chars vs eight. That's why dumps show hex, not binary. See hex.

Quick Table 0 to 15 — Memorize This

Dec: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hex: 0 1 2 3 4 5 6 7 8 9  A  B  C  D  E  F
Bin: 0000 0001 0010 0011 0100 ... 1111 (4 bits each)

After 15, hex carries: 10₁₆ =16 decimal, 1F₁₆ =31, 20₁₆ =32.

How to Convert — Divide by Base vs Multiply Place

Conversions decimal to binary divide by 2 binary to decimal place value

Decimal → Binary (or any base): divide by base, collect remainders bottom-up:

10 ÷2 =5 r0 ↑
 5 ÷2 =2 r1 ↑
 2 ÷2 =1 r0 ↑ → read up: 1010₂
 1 ÷2 =0 r1

Decimal 13 → 1101₂, decimal 26 → 11010₂. Try via our binary converter — enter 10 decimal → see 1010₂, 0xA, 0o12 at once.

Binary → Decimal: multiply place: 1010₂ =1×8+0×4+1×2+0×1=10, 1101₂=8+4+0+1=13.

Decimal → Hex: divide by 16: 26 ÷16=1 r10(A) → read up: 1A₁₆ (1×16+10=26). 255 ÷16=15 r15(F) → 15 r15 → FF₁₆. Use our convert decimal to hex — handles 10→A, padding, 0x prefix. Decimal → Octal divide by 8 similarly via our convert decimal to octal — 10÷8=1 r2 → 12₈.

Hex ↔ Binary — Group 4 Bits (No Math)

Binary → Hex: group 4 bits 1010 1100₂ → A C → AC₁₆. Hex → Binary: expand per digit A=1010, F=1111 → FF₁₆ =11111111₂. That's why 0xFF is byte shorthand — 255.

Why Hex Exists — Colors, Memory Addresses, and Compactness

Why hex colors #FF5733 memory 0xFF binary flags

Colors — #RRGGBB: #FF5733FF₁₆=255 red, 57₁₆=87 green, 33₁₆=51 bluergb(255,87,51). Each channel 0-255 (one byte) → 2 hex digits. #000000 black (0,0,0), #FFFFFF white (255,255,255). So hex is color picker — 6 hex digits = 3 bytes. See MDN hex color.

Memory — 0x: Address 0x7FFF5FBF hex is compact vs 32-bit binary 32 chars; byte 0xFF is 8 ones. Debuggers show hex.

Binary flags — 0b: Permission 0b1010 =10 =0xA as bit mask READ=0b0001, WRITE=0b0010. Networking mask 255.255.255.0 = 0xFFFFFF00.

Octal Legacy — chmod 755

Unix chmod 755 is octal: 3 bits per digit → 7=111 rwx, 5=101 r-xrwxr-xr-x (owner rwx, group r-x, other r-x). Base 8 fits 3 bits, legacy but still standard. See chmod. Modern prefers 0o755 prefix.

Quick Reference Table — 0 to 32 in Binary, Octal, Hex, Decimal

Quick table 0 to 32 binary octal hex decimal
Dec  Bin(8-bit)  Hex   Oct  Note
 0   00000000    0x00  0o00  Zero
 1   00000001    0x01  0o01
10   00001010    0x0A  0o12  A=10
15   00001111    0x0F  0o17
16   00010000    0x10  0o20  10 hex =16
31   00011111    0x1F  0o37
32   00100000    0x20  0o40  Space ASCII 32 =0x20
255  11111111    0xFF  0o377 Max byte

ASCII: A=65=0x41=01000001₂, a=97=0x61. Color white 255,255,255 = 0xFFFFFF.

Pitfalls — Leading Zeros, Prefixes, and Signed

Pitfalls prefixes 0b 0x 0o signed unsigned
  • Prefixes: In JS/Python, 0b1010 binary, 0xA hex, 0o12 octal — bare 010 may be parsed as octal in some contexts (use 0o10). Binary string "10" could be 2 or 10 — always note base 1010₂ or prefix.
  • Leading zeros: 1010₂ vs 01010₂ same value (leading zero no effect) but string length matters for byte padding — pad to 8 bits 00001010 for byte.
  • Signed vs Unsigned: 8-bit 11111111₂ = 255 unsigned but −1 signed in two's complement — know width (8/16/32-bit). Check two's complement.
  • HSB/LSB: when reading binary string left-to-right, leftmost is most significant (128 for 8-bit). Don't reverse.

Use converters for edge: paste 0xFF → see 255, 11111111₂, handling 0b/0x/0o and padding. They handle sign and width you select.

Bitwise Tip — Powers of Two Are Single 1

1₂=1, 10₂=2, 100₂=4, 1000₂=8 — powers of two are 1 followed by zeros. Need to know if n is power of two? (n & (n-1)) === 0 in code — binary insight.

ASCII, Unicode, and Bytes — Why 65 = 0x41 = 'A'

Computers store characters as numbers per encoding. ASCII (7-bit, 0-127): A=65=0x41=01000001₂, a=97=0x61, 0=48=0x30, space=32=0x20. UTF-8 extends this — é=0xC3A9 (2 bytes). Hex dumps show bytes: 48 65 6C 6C 6F → "Hello". Example 4-byte word 0x41424344 in hex dump is "ABCD" in ASCII. See ASCII table and MDN charCodeAt.

Why 255 Is Everywhere

255 = 11111111₂ = FF₁₆ = 0xFF = 377₈ is max unsigned 8-bit byte (2⁸-1). So IPv4 byte 192 max 255, color channel 0-255, file byte 0-255. Next value 256 needs 9 bits → 100000000₂ = 0x100 spills to 2 bytes. That's why 0xFF +1 = 0x100 overflow is classic bug.

IP Addresses — Decimal Dotted, Binary Underneath

IPv4 192.168.1.10 is four bytes decimal dotted → binary/hex:

192 → 11000000₂ → 0xC0
168 → 10101000₂ → 0xA8
1   → 00000001₂ → 0x01
10  → 00001010₂ → 0x0A
IP hex: 0xC0A8010A (32-bit)
Subnet /24 mask 255.255.255.0 → 11111111.11111111.11111111.00000000₂ → 0xFFFFFF00

Mask /24 is 24 ones then 8 zeros. Subnet math is binary AND: IP & Mask = Network. See IPv4 and bitwise.

Binary Arithmetic — Add, Shift, and Powers of Two Trick

Add binary like decimal but carry on 1+1=10₂:

 1010 (10)
+ 0011 (3)
= 1101 (13)  // 0+1=1, 1+1=10 carry, etc.

Shift left 1010 <<1 =10100₂ (20) =×2, right 1010 >>1=0101₂ (5)=÷2 — powers of two are 1 followed by zeros: 1,10₂=2,100₂=4,1000₂=8,10000₂=16. Need to know if n is power of two? (n & (n-1)) === 0 in code — binary insight. See binary arithmetic.

Negative — Two's Complement

Signed 8-bit: 00000001₂=+1, 11111111₂= -1 (invert +1). Range -128 to +127 vs unsigned 0-255. Know width — same bits mean different values. See two's complement.

Octal Deep Dive — Why It Faded but Persists in Permissions

Base 8 fits 3 bits (0-7 = 000-111), so early 12-bit PDP-8 used octal compactly. Today hex fits 4 bits (byte) better, so hex won. Octal remains only in Unix chmod permissions as above and in Python legacy 010 literal (now 0o10). Prefer hex for new code unless permission — use 0o755 not 0755 (ambiguous).

Quick converter check — Copy these 3:
Decimal 42 → Binary 101010₂ → Hex 0x2A → Octal 0o52
Hex #FF5733 → R 0xFF=255, G 0x57=87, B 0x33=51 → rgb(255,87,51)
Binary 11111111₂ → 255 → 0xFF → 0o377 (max byte, all ones)
Paste into converters to verify — handling 0b/0x/0o prefixes and padding to 8 bits.

Floating Point — Not All Binaries Are Integers

Binary fractions use negative powers: 101.11₂ =1×4+0×2+1×1 +1×0.5+1×0.25=4+1+0.5+0.25=5.75. IEEE 754 double packs sign×mantissa×2^exponent — hence 0.1 +0.2 =0.30000000000000004 in JS: decimal 0.1 is repeating binary 0.000110011... → round error. Hex float? 0x1.8p10 means 1.5 ×2^10 =1536 per C99 hex float. For money, store cents as integer 1999 not 19.99 float. See IEEE 754.

Big Numbers and Limits — 32-bit, 64-bit, and BigInt

32-bit unsigned max 11111111 11111111 11111111 11111111₂ = 0xFFFFFFFF =4294967295 (4B). Signed max 01111111... =2147483647. JavaScript number is 53-bit int safe max 9007199254740991 =0x1FFFFFFFFFFFFF — beyond loses, hence API IDs as strings. Use BigInt("9007199254740993") and 0x1FFFFFFFFFFFFF_n for bigger. See MDN BigInt.

Hex for Hashes and UUIDs

Git commit a1b2c3d4e5f6, UUID 550e8400-e29b, SHA256 e3b0c44298fc... — hex because length: 20 bytes = 40 hex chars vs 160 bits. Binary would be 160 chars. Hex is human view of bytes.

Endianness — Which Byte First?

Number 0x12345678 stored as bytes: big-endian 12 34 56 78 vs little-endian 78 56 34 12 (x86 is little-endian). Hex dump 78 56 34 12 reversed is endianness, not value change — interpret via tool's endian toggle.

Common Questions — Top and Bottom N Bits

Want top 4 bits of byte 11110101₂ (0xF5)? Shift right 4: 0xF5 >>4 =0x0F or mask 0xF5 & 0xF0 =0xF0. Bottom 4 bits: 0xF5 & 0x0F =0x05. Hex masks are readable: 0xFF00 vs binary 1111111100000000₂.

Practice — Convert Without Calculator First, Then Verify:
Decimal 42 → /2: 42r0,21r1,10r1,5r0,2r1,1r1 → read up: 101010₂ → group 4: 0010 1010 → 0x2A
Check: 0x2A =2×16+10=42 ✓
Hex #0F0 = 0x0F=15 → binary 00001111₂ → 4 bits each
Hand first for learning, tool for prod — converters handle prefix and padding correctly.

History — Why We Use Base 10 and Computers Don't

Base 10 stuck because of 10 fingers — Sumerians used base 60 (still in 60 seconds/min, 360 degrees). Computers use base 2 because transistor is on/off per Leibniz binary (1703) and Shannon's 1937 Boolean mapping. Hex shorthand emerged with 8-bit bytes (1960s IBM) — 4 bits per hex made dumps readable vs 8-bit binary walls. Octal was PDP-8 era (12-bit = 4 octal digits), faded after bytes standardized to 8. Understanding history explains why docs say "hex color" not "binary color" — human compactness.

UTF-8, Bytes, and Hex Dumps — Reading Memory

File "Hi" is bytes 48 69 hex → 01001000 01101001₂ → ASCII "Hi". Hex dump tool xxd shows 00000000: 4869 6C6C 6F0A → "Hello\n". Each pair hex = one byte. So #FF5733 color's three bytes FF 57 33 are directly dump-visible. See hex dump.

Bit vs Byte vs Nibble

Bit = one binary digit (0/1), Nibble =4 bits =1 hex, Byte=8 bits =2 hex, Word=16/32 bits. So 0xAB is byte 10101011₂ = two nibbles A B.

Checks and Pitfalls — When Hex Lies

PitfallFix
Binary "10" no baseWrite 1010₂ or 0b1010 — "10" could be 2 or 10
Leading 0 in JS 010Old JS octal trap — use 0o10 explicit per MDN
Signed 255 vs -1Know 8-bit width: 0xFF unsigned 255, signed −1 — check two's complement
Hex color #FFF shorthand#FFF#FFFFFF white — 3-digit expands per channel, not 3 total
Record — Keep Base Noted:
Always log as "1010₂" or "0xFF" not "10" or "FF" bare — future reader knows base, not guessing.
Bare "10" caused Mars Climate Orbiter mixup (lb vs N) — base/unit labels prevent class of error.

Real Conversions — Worked With Remainders (Check With Tool)

Do 173 decimal → hex, then verify via converter:

173 ÷16=10 r13(D) → 10 decimal = A? Wait 13=D, 10=A
173 ÷16=10 r13(D) ↑ → 10 ÷16=0 r10(A) ↑ → read up AD₁₆
Check: A=10×16=160 +13=173 ✓
Binary: 10→1010, 13→1101 → 10101101₂? Actually AD= 1010 1101₂ → 173 decimal.

Another: Decimal 42 → binary divide 21r0,10r1,5r1,2r0,1r1 → 101010₂ → hex group 0010 1010 → 0x2A. Decimal 777 → octal divide by 8: 97r1,12r1,1r4 → 1411₈ (1×512+4×64+1×8+1=777).

Hex for Permissions Deep — rwxr-xr-x to 755 to UGO

chmod 755 file → binary per digit: 7=111 rwx, 5=101 r-xrwxr-xr-x. Symbolic chmod u+rwx,g+rx,o+rx same. Octal fits because permission bits are 3 per category — hex would be 2 bits waste. Modern 0o755 prefix clarifies base. See chmod.

Floating Binary — Why 0.1 + 0.2 ≠ 0.3 and Hex Floats

Decimal 0.1 is binary 0.0001100110011... repeating → float rounds → 0.30000000000000004. Hex float 0x1.99999Ap-4 is exact per IEEE 754 hex significand p exponent. For money, integer cents avoid. For display, toFixed(2) hides binary.

Production pattern — Store Money as Integer:
// Bad: 19.99 + 0.01 → 20.000000000000004
// Good: 1999 cents + 1 cent = 2000 cents → 20.00 display via 2000/100
const cents = 1999; // integer
Binary fraction insight saves fintech bugs.

Use Cases — When You Reach for Each Base

  • Binary: bit flags 0b0001 READ, 0b0010 WRITE, 0b0100 EXEC → combine READ|WRITE =0b0011=3, check flags & READ. Use bitwise for feature toggles.
  • Hex: colors #FF5733, memory 0x7FFF, hash a1b2c3, UUID 550e8400-e29b.
  • Octal: permissions 0o755, legacy PDP-11. New code hex unless permission.
  • Decimal: human I/O, money display (store integer), counts.

Common Questions — Top and Bottom N Bits, Masking

Want top byte of 0xABCD =1010101111001101₂? 0xAB is top 8 bits: 0xABCD >>8 =0xAB or mask 0xABCD & 0xFF00 =0xAB00 then shift. Bottom byte: 0xABCD & 0x00FF =0xCD. Hex masks readable: 0xFF00 vs binary 1111111100000000₂.

Bonus: keep base noted — "1010₂" or "0xFF" not "10" or "FF" bare — future reader knows base, not guessing.

Bit vs Byte vs Nibble Revisited

Byte 8 bits = 2 hex digits = 1.5 octal digits (awkward). That's why hex beat octal after bytes standardized — 2 hex per byte is clean, 2.66 octal per byte is messy.

Hands-On Lab — Convert Without Tool, Then Verify

Decimal 123 → Binary: 61r1,30r1,15r0,7r1,3r1,1r1 → read up 1111011₂
→ Hex group 0111 1011 → 0x7B (7×16+11=123 ✓)
→ Octal 123÷8=15r3,1r7,0r1 → 173₈ (1×64+7×8+3=123 ✓)
Check: 0x7B = 7×16+11=123, 173₈=1×64+7×8+3=123

Do 255 → 11111111₂ → 0xFF → 0o377. Then paste 0xFF into binary converter to see 255 and 11111111₂ handling 0x and padding to 8 bits.

Width Matters — Pad to Byte

10 decimal = 1010₂ shortest, but byte padded 00001010₂ shows full 8 bits. Hex 0x0A padded to byte 0x0A vs 0xA — same value, byte view needs two hex digits. Use 8-bit 00001010 when talking bytes.

Record — Keep Base Noted, Pad to Byte:
Always log as "1010₂" or "0xFF" not "10" or "FF" bare — and pad binary to 8 bits when discussing bytes.
Bare "10" caused unit mixups — base/unit labels prevent class of error.

Common Questions — Top and Bottom N Bits, Masking Revisited

Want bottom 8 bits of 0x12340x34 (low byte): 0x1234 & 0xFF =0x34. Top 8 bits: (0x1234 >>8) & 0xFF =0x12. Hex masks are readable vs binary 11111111₂.

Copy working 1010₂ template — one correct reused beats four hand-typed with different base mistakes.

Validate early, fail fast at parse — not at runtime when parseInt("FF",16) on bare "FF" vs "0xFF" confusion crashes. Always specify radix parseInt(str, 16).

Keep one source — committed binary/hex for docs with base noted, wire decimal for display — choose per context.

Version your examples — v1 with 1010₂, v2 adds 0xFF — so git diff shows which base was added when 255 changed.

Keep base noted — "1010₂" or "0xFF" not "10" or "FF" bare — future reader knows base, not guessing.

Validate early — parseInt("FF",16) → 255 vs parseInt("FF",10) → NaN — always pass radix.

Frequently Asked Questions

What is the difference between binary, decimal, and hex?

Decimal base 10 digits 0-9 for humans; binary base 2 digits 0-1 for computers (on/off); hex base 16 digits 0-9+A-F compact binary (4 bits per hex). Same value: 10 decimal = 1010 binary = A hex = 12 octal.

Why do computers use binary?

Transistor has two states — high/low voltage → 0/1. Binary maps directly to hardware gates. Hex is human shorthand for binary bytes.

How do I convert decimal to binary?

Divide by 2, collect remainders bottom-up: 10÷2=5 r0, 5÷2=2 r1, 2÷2=1 r0, 1÷2=0 r1 → read up 1010₂. Or use binary converter.

How do I convert hex to decimal?

Multiply place: 1A₁₆ =1×16+10=26, FF₁₆=15×16+15=255. Use convert decimal to hex in reverse via divide by 16.

What is 0xFF?

Hex FF = 255 decimal = 11111111₂ binary = one byte all ones. Prefix 0x denotes hex in code.

Why is chmod 755 octal?

Permissions are 3 bits per category (rwx): 7=111 rwx, 5=101 r-x. Base 8 fits 3 bits, so 755 octal = rwxr-xr-x. Use 0o755 in modern Python.