Number Base Converter
This number base converter is exact in every base, including values past 2^53 where a floating-point one quietly loses digits.
In decimal
- In binary
- 11111111
- In octal
- 377
- In decimal The value as entered.
- 255
- In hexadecimal
- ff
- Grouped Binary in nibbles of four and hex in bytes of two, which is how both are actually read. Each hex digit is exactly four binary digits, so the two groupings line up. That correspondence is the whole reason hexadecimal exists.
- 1111 1111 | ff
- Fits in Unsigned. A value needing more than 53 bits cannot be held exactly in a JavaScript number, which is why this converter works in BigInt. A float-based converter is silently wrong in the last digits above that.
- 8 bits
- As a character Read as a Unicode code point. This is the 'binary to text' conversion, one character at a time: 65 is A, 97 is a, and the 32 between them is why setting the sixth bit changes case in ASCII.
- U+00FF ΓΏ
How the Number Base Converter works
A number has one value and many spellings. Two hundred and fifty-five is 255 in decimal, FF in hexadecimal, 377 in octal and 11111111 in binary, and converting between them changes how the number is written and nothing about the quantity, so a binary converter, a hex converter and an octal converter are one tool with three settings. Every base works the same way: each digit position is worth the base times the position to its right.
Binary exists because a wire is either carrying a voltage or not, so every value in a computer is ultimately a string of bits. Hexadecimal exists because binary is unreadable at length, and because sixteen is two to the fourth: each hex digit stands for exactly four binary digits, with no carrying between them. That is why 11111111 is FF and not some unrelated pair of symbols, and why a programmer reads a 32-bit value as eight hex digits rather than thirty-two ones and zeros. Octal has the same property with three bits per digit, which is why Unix file permissions are octal: read, write and execute are exactly three flags, so 755 is three groups of three bits.
Negative numbers are where the representation stops being cosmetic. A computer stores them in two's complement: to get -5 in eight bits, take 5 (00000101), invert every bit (11111010) and add one (11111011). The leading bit then acts as a sign, and the scheme is used instead of the more obvious sign-and-magnitude because addition works unchanged: adding 5 and -5 in this representation carries out to zero without any special case for signs. It also makes the range asymmetric: a signed byte holds -128 to 127, because zero occupies one of the slots that would otherwise be a positive.
One thing this converter does that most online converters do not: it works in exact integers all the way up. JavaScript numbers are doubles and lose integer precision above 2^53, which is about 9 quadrillion. That sounds like plenty and is not: a 64-bit hash, a permissions mask, a Unix timestamp in nanoseconds and a Discord snowflake are all routinely larger, and a converter built on floating point returns a wrong answer for them with no indication anything went wrong. This one uses arbitrary-precision integers, so every digit is exact at any size.
And nothing here guesses. A value with a digit that does not belong to its base returns an error rather than a partial result, because the standard library behavior (stopping at the first bad character and returning what came before it) turns a typo into a believable wrong number.
Number Base Converter FAQ
How do I convert binary to decimal by hand?
Add up the place values where there is a 1. The rightmost bit is worth 1, then 2, 4, 8, 16 and so on, doubling to the left. So 1011 is 8 + 0 + 2 + 1 = 11. Going the other way, repeatedly halve and write down the remainders, then read them bottom to top.
Why is hexadecimal used instead of binary?
Because sixteen is two to the fourth, so one hex digit is exactly four bits with no carrying between them. That makes the translation purely positional (you can convert a hex string to binary digit by digit without doing any arithmetic) while cutting the length by three quarters. 11111111 and FF are the same number and only one is readable.
What does 0x mean?
It is a prefix marking the digits that follow as hexadecimal, and it comes from C. 0b marks binary and 0o marks octal in most modern languages; older ones used a bare leading zero for octal, which is why 010 means 8 in C and is a famous source of bugs. This converter accepts all three prefixes and also works without them.
How are negative numbers stored in binary?
Two's complement: invert all the bits of the positive value and add one. The top bit then indicates the sign, and ordinary binary addition works for signed values with no special handling. It is also why the negative range extends one further than the positive: a signed byte goes from -128 to 127.
Why do some converters give wrong answers for large numbers?
Because they use floating-point arithmetic, which holds integers exactly only up to 2^53. Past that, digits are silently rounded. 64-bit identifiers, hashes and masks are all past it, so the answer looks right and is not. This converter uses arbitrary-precision integers and has no such limit.
What is a nibble?
Four bits: half a byte, and exactly one hexadecimal digit. The grouped output above splits binary into nibbles for that reason: each group of four maps to one hex character, so you can read the two forms against each other.