Skip to content
WebTricks

Number base converter

Convert numbers between binary, octal, decimal and hexadecimal. Type in any base, read all four.

BIN11111111
OCT377
DEC255
HEXff

What this base converter does

Enter a non-negative integer in binary, octal, decimal or hexadecimal and read the same value in all four bases at once. Each digit is validated against the selected base before conversion, so a 2 in a binary field or a g in a hex field is reported as an error instead of being silently truncated the way parseInt would. Values up to 2^53 − 1 are supported exactly; everything runs in your browser.

How to use it

  1. Choose the Input base — Binary (2), Octal (8), Decimal (10) or Hex (16).
  2. Type the number without a prefix (no 0x, 0b, #).
  3. The BIN / OCT / DEC / HEX rows update as you type; hex output is lowercase.
  4. Click Copy next to the row you need.

Worked examples

DecimalBinaryOctalHexWhy you meet it
10101012aFirst hex letter
12711111111777fLargest signed 8-bit value; 127.0.0.1
25511111111377ffOne full byte; max RGB channel
4931111011017551edchmod 755
1000111110100017503e81 ms in µs
10241000000000020004001 KiB
655351111111111111111177777ffffMax port number, 16-bit max
429496729532 ones37777777777ffffffff32-bit unsigned max

Converting by hand works on the same idea in every base: repeatedly divide by the base and read the remainders backwards. 255 ÷ 16 = 15 remainder 15 (f), 15 ÷ 16 = 0 remainder 15 (f), so 255 = ff.

Bit tricks worth memorizing

Hex ↔ binary is a lookup, not a calculation. Each hex digit maps to a 4-bit group (a nibble): 3e8 = 0011 1110 1000. Pad the binary number to a multiple of 4 on the left and translate group by group. Octal works the same way with 3-bit groups: 755 = 111 101 101.

Powers of two have a single 1 bit. 1024 = 10000000000 (a 1 followed by ten zeros), so n & (n - 1) === 0 is the classic power-of-two test.

Masks. 0xff keeps the low byte, 0xffff the low two bytes. To pull the green channel out of 0x1e90ff: shift right by 8 and mask, (0x1e90ff >> 8) & 0xff = 0x90 = 144.

Permissions. Each octal digit is rwx as 4+2+1. 7 = 111 = rwx, 5 = 101 = r-x, 4 = 100 = r—, 6 = 110 = rw-. So 644 is rw-r--r--.

Reading a hex dump. Two hex characters per byte; 48 65 6c 6c 6f is Hello in ASCII, because 0x48 = 72 = H.

Doing it in JavaScript

parseInt('ff', 16);        // 255   — parse from a base
(255).toString(2);         // '11111111' — format to a base
(255).toString(16).padStart(4, '0'); // '00ff'
0b1010 + 0o17 + 0xff;      // literals: 10 + 15 + 255 = 280
Number('0x1f');            // 31 — Number() understands prefixes, parseInt(…, 16) does not need them

Two things catch people out. parseInt('12', 2) returns 1, not an error — it stops at the first invalid digit, which is why this tool validates the whole string first. And numbers above Number.MAX_SAFE_INTEGER need BigInt: BigInt('0xffffffffffffffff').toString(2) works, while the plain Number version rounds.

Bitwise operators (&, |, >>, ~) in JavaScript work on 32-bit signed integers, so 0xffffffff | 0 is -1 and 1 << 31 is negative. Use >>> 0 to read the result as unsigned, or BigInt for 64-bit work.

  • Color converter — a hex color is just three bytes; convert #1e90ff to rgb(30, 144, 255) and other spaces.
  • Hash generator — digests are long hex strings; see how many bits 64 hex characters represent.
  • UUID generator — 32 hex digits = 128 bits, grouped 8-4-4-4-12.
  • CSS unit converter — a different kind of conversion: px, rem, em and viewport units.
  • Timestamp converter — Unix timestamps are often shown in hex in logs and packet captures.

FAQ

Why are colors and bytes written in hex?

Each hex digit is exactly 4 bits, so two digits are one byte (0–255). A color like #1e90ff is three bytes — red 0x1e = 30, green 0x90 = 144, blue 0xff = 255 — and you can read each channel without any arithmetic.

What is the biggest number it handles?

Up to 9007199254740991 (2^53 - 1, JavaScript's Number.MAX_SAFE_INTEGER), which is 53 ones in binary or 1fffffffffffff in hex. Larger values would silently lose precision, so the tool shows an error instead.

Can I type 0x, 0b or 0o prefixes?

No — enter bare digits and choose the input base from the dropdown. ff with Hex selected is the same as 0xff in code. A prefix is flagged as an invalid digit.

Does it support negative or fractional numbers?

No, only non-negative integers. Negative numbers in binary depend on the word size (8, 16, 32 or 64-bit two's complement), so there is no single right answer without that context.

Why does my hex input show as invalid?

Hex accepts 0–9 and a–f in either case; anything else — a space, a # from a color, a g — fails validation. Likewise binary only accepts 0 and 1 and octal 0–7.

What is octal used for today?

Mostly Unix file permissions. chmod 755 is octal — each digit is three bits (read, write, execute) for owner, group and others, so 755 means rwxr-xr-x.