Number Base Converter
One value, every representation. Enter it in whichever base you have and read off the rest, including the two’s complement forms that matter when a number has to fit in a fixed number of bits.
Value
Prefixes 0x, 0b and 0o are understood and set the base automatically.
Fixed-width representations
Why 2, 8, 16 and not 7 or 13
Hardware is binary, but binary is unreadable at length. Because 8 and 16 are both powers of two, converting between them and binary needs no arithmetic at all — every hex digit is exactly four bits, every octal digit exactly three. 0xFF is 1111 1111 by inspection. That property is the whole reason those bases became standard, and it is why base 10 is the awkward one in computing.
Two's complement: how negatives are stored
Flip every bit and add one. In 8 bits, −1 becomes 11111111 and −128 becomes 10000000. The reason this representation won is that addition and subtraction need no special case — the same adder circuit handles signed and unsigned values identically, and the carry out of the top bit is simply discarded.
It also explains the asymmetry every programmer meets eventually: an 8-bit signed value ranges from −128 to +127, not −127 to +127, because zero takes up one of the positive slots.
Reading the place-value breakdown
Every base works identically: each digit is multiplied by the base raised to its position, counting from zero on the right. 1011 in binary is 8 + 0 + 2 + 1 = 11. 2F in hex is 2×16 + 15 = 47. The breakdown above spells this out digit by digit, which is the fastest way to convert by hand and to spot a mis-typed digit.
Bits, bytes and why the count matters
The number of bits needed is ⌊log₂(n)⌋ + 1. It determines whether a value fits in a field, how wide a database column has to be, and how many distinct values an identifier can hold. 255 needs 8 bits and fills a byte exactly, which is why it is the boundary that shows up everywhere from colour channels to IPv4 octets.
Frequently Asked Questions
How do I convert hex to decimal by hand?
What does the 0x prefix mean?
Why does an 8-bit signed number stop at 127?
What is the highest base supported?
Sources
Official publications only. Links open the original document in a new tab.
- National Institute of Standards and Technology SP 800-63B — Digital identity guidelines: authentication Digital identity and authentication guidance