How to convert a number between bases
- Type or paste your number into the Number box, for example
255,0xFFor0b1111. - Leave Read the number as on Auto, or choose binary, octal, decimal or hexadecimal if your number has no prefix.
- 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_0000are accepted. - The leading zeros of a fixed width value are not kept, because a number does not remember its width.
- File permissions like
0o755and bit flags are easiest to read in octal and binary. - Changing a colour from
#FF8800to 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.