Skip to content
PocketDesk
Your files are processed on your device, never uploaded

Number base converter

  • On device

Result

Working

How to convert a number between bases

  1. Type or paste your number into the Number box, for example 255, 0xFF or 0b1111.
  2. Leave Read the number as on Auto, or choose binary, octal, decimal or hexadecimal if your number has no prefix.
  3. The binary, octal, decimal and hexadecimal forms appear straight away, together with the number of bits needed. Use Copy to take all four.

What number bases are

We normally write numbers in base 10, using ten digits. Computers work in base 2, because a circuit is either on or off. Binary numbers get long quickly, so programmers also use base 8 (octal) and base 16 (hexadecimal), where each digit stands for exactly three or four bits. Hex is everywhere: colours like #2B55E0, memory addresses, file signatures and hashes.

To convert by hand you add up each digit times a power of the base. In hexadecimal FF is 15 times 16 plus 15, which is 255. The converter does this for you and checks that each digit is valid for the base, so 2 in a binary number or G in a hex number gets a clear error.

Exact results for huge numbers

Normal JavaScript numbers lose precision beyond 9,007,199,254,740,991 (2 to the power of 53, minus 1). This tool does all its work with BigInt, which has no size limit, so a 256 bit key or a long identifier is converted digit for digit. Try a value such as 0xffffffffffffffffffffffffffffffff to see a 128 bit number in all four bases.

Tips

  • Group binary digits in fours, and hex digits in twos, to read them more easily. Underscores such as 1111_0000 are accepted.
  • The leading zeros of a fixed width value are not kept, because a number does not remember its width.
  • File permissions like 0o755 and bit flags are easiest to read in octal and binary.
  • Changing a colour from #FF8800 to its red, green and blue values? Use the color converter.
  • Timestamps in hex or binary can be compared against dates with the Unix timestamp converter.
  • For random keys, the password generator uses your browser’s secure generator.

Everything is calculated on your device, and nothing is sent anywhere.

Questions

How big a number can I convert?

Any size. The tool uses BigInt arithmetic, so numbers with hundreds of digits stay exact, unlike calculators that round after 15 or 16 digits.

How do prefixes work?

In Auto mode, 0x means hexadecimal, 0b binary and 0o octal. Without a prefix the number is read as decimal. Pick a base to override that.

Are negative numbers supported?

Yes. A leading minus sign is kept, so -255 gives -11111111 in binary and -FF in hex.

Can I use spaces or underscores?

Yes. Spaces, commas and underscores are ignored, so 1111_0000 and 1 000 000 both work.

More developer tools