Convert between decimal, binary, octal, and hex with BigInt

Decimal, binary, octal, hex.

Edit any base and see the others update in sync. Supports arbitrary precision via BigInt and shows invalid input gracefully. Pure browser; no login.

Binary, octal, decimal and hex number systems

A number system, or base, decides how many different digits you count with before carrying over to the next position. We count in base 10. Computers work in base 2, binary, because a circuit is either on or off. Programmers also use base 16, hexadecimal, as a compact way to write binary, and base 8, octal, for Unix file permissions.

This converter keeps all four bases in sync. Type into any field and the others update, with exact results for numbers of any size, because it uses JavaScript's arbitrary-precision BigInt instead of ordinary floating-point numbers.

How to use it

  1. Type a number into the field of the base you have: decimal, binary, octal or hex.
  2. Read the same value in the other three bases.
  3. Use a leading minus sign for negative numbers in any base.
  4. If you type a digit that does not exist in that base, such as 2 in binary or g in hex, the field is marked invalid.

Example: 255, the largest byte

Input
255 (decimal)
Output
Binary: 11111111
Octal: 377
Hex: FF

Eight ones in binary, which is two F digits in hex: every hex digit stands for exactly four binary digits.

How positional bases work

In any base, each position is worth the base raised to a power, counting from zero on the right. The binary number 1011 is 1×8 + 0×4 + 1×2 + 1×1 = 11. The hex number 2F is 2×16 + 15 = 47, because hex uses the letters A to F for the values 10 to 15.

To convert between binary and hex by hand, group the binary digits in fours from the right and replace each group with one hex digit: 1010 1111 becomes AF. Octal works the same way with groups of three, which is why chmod 755 maps neatly to rwx bit triplets.

Big numbers stay exact

Ordinary JavaScript numbers lose precision above 9,007,199,254,740,991, so many online converters silently round large values such as 64-bit IDs, hashes or cryptographic keys. This tool uses BigInt arithmetic, so a 40-digit hex value converts to decimal and back without losing a single digit.

Negative numbers

This converter writes negative numbers with a minus sign in every base: −5 is −101 in binary. Processors store negative integers differently, in two's complement, where the same 8-bit pattern 11111011 means −5. To see that form, add 2 to the power of the bit width to the negative number first: for 8 bits, −5 + 256 = 251, which is 11111011.

Questions

Can I type a 0x or 0b prefix?

Type the digits without a prefix; the field already says which base it is in.

Does it support fractions?

No, whole numbers only. Fractions in other bases often do not terminate, just as one third does not in decimal.

Why is hex shown in capital letters?

Capitals are easier to read next to digits. The hex field accepts lower case too.