HandyBench

Number Base Converter

Convert binary, octal, decimal and hex.

Binary0b11111111
Octal0o377
Decimal255
Hexadecimal0xff
Base 3673

How to use the Number Base Converter

  1. 1 Enter a number (a leading minus sign is fine) and select its current base.
  2. 2 Read the value in binary, octal, decimal, hexadecimal and base 36.
  3. 3 Copy the representation you need.

How the conversion works

You choose the base the value is written in, and the page shows the same number in binary (base 2), octal (base 8), decimal (base 10), hexadecimal (base 16) and base 36. The input base list offers the same five bases. Internally it reads each digit left to right, multiplying a running total by the base and adding the digit, using JavaScript BigInt. It then prints that integer in each of the five bases. Since BigInt has no 64-bit limit, nothing is rounded; 18446744073709551616 (2 to the power of 64) converts exactly to 10000000000000000 in hex.

DecimalBinaryOctalHex
10101012a
16100002010
25511111111377ff
256100000000400100
1024100000000002000400

Worked example

Entering 255 with the input base set to decimal gives 0b11111111, 0o377, 255, 0xff and 73 in base 36 (7 x 36 + 3). Check by hand: 255 = 15 x 16 + 15, and 15 is f, so hex is ff. Each hex digit is exactly four bits, which is why ff is eight ones in binary. That 4-bit link is why programmers use hex as shorthand for binary: a byte is always two hex digits.

Input rules and pitfalls

  • Output prefixes. Results are shown with 0b, 0o and 0x in front (decimal and base 36 have none), and the Copy button copies the prefix and any minus sign as well. Letters are lower-case. Base 36 uses the digits 0 to 9 and the letters a to z, which is how many short IDs and URL codes are written.
  • Underscores are ignored, so 1111_1111 in binary reads as 255. Surrounding whitespace is trimmed.
  • A prefix is stripped only when it matches the input base. In binary mode a leading 0b is dropped, in octal mode 0o, and in hexadecimal mode 0x. In any other combination the characters are read as digits, so in hexadecimal mode 0b11 is the hex number 0xb11 (2833 in decimal), and in decimal mode it is rejected because b is not a decimal digit.
  • Invalid digits are named in the error, such as "2" is not a valid digit for base 2.
  • Negative numbers use a sign, not two's complement. A leading - (or +) is accepted, and the result is the same magnitude with a minus sign in every base: -ff in hex gives -255 in decimal and -0b11111111 in binary. For a fixed-width two's-complement bit pattern, such as 11111111 for -1 in 8 bits, you still need to pick a word size yourself.
  • Whole numbers only. Fractions such as 0.5 are not converted.

To turn letters into their numeric codes rather than convert numbers, use text to ASCII or binary to text. For file sizes in KB versus KiB, see the data storage converter, and for non-positional numerals, the Roman numeral converter.

Examples

  • ▸ Converting 255 (decimal) to FF (hex).
  • ▸ Reading a hex color or byte value in binary.

Frequently asked questions

Does it handle very large numbers?

Yes. It uses arbitrary-precision big integers, so even numbers far beyond 64 bits convert exactly without rounding.

Can I paste values with 0x or 0b prefixes?

Yes, when the prefix matches the input base: 0x in hexadecimal, 0b in binary, 0o in octal. Underscores used as digit separators are ignored. A prefix that does not match is read as digits, so in hexadecimal mode 0b11 is the hex number 0xb11 (2833), not 11.

Can it convert negative numbers or fractions?

Negative whole numbers work: -ff in hex gives -255 in decimal and -0b11111111 in binary, shown as a sign plus the magnitude. This is not a fixed-width complement form, so for a bit pattern of a given width you still pick the word size yourself. Fractions such as 0.5 are not accepted.

How do I convert hexadecimal to binary?

Set the input base to Hexadecimal and type the value, for example ff. The Binary row shows 11111111, because each hex digit maps to exactly four binary digits.

Why do programmers use hexadecimal?

One hex digit stands for exactly four bits, so a byte is always two hex digits. That makes colours, memory addresses and byte values much shorter to read than binary.