What a base is, and how to read place values
A base (or radix) says how many distinct digits a number system uses and therefore how much each place is worth compared with the one to its right. In everyday decimal, "253" means 2 x 102 + 5 x 101 + 3 x 100. Binary "1101" is read in exactly the same way: 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 = 8 + 4 + 0 + 1 = 13. In any base, multiply each digit by the base raised to its position and add the results to get the decimal value. The "positional expansion" shown in the working below is that sum.
Going the other way, to convert a decimal number to base N, divide by N repeatedly and read the remainders from last to first. For 13: 13 / 2 is 6 remainder 1, 6 / 2 is 3 remainder 0, 3 / 2 is 1 remainder 1, and 1 / 2 is 0 remainder 1. Reading the remainders backwards gives 1101. They come out in reverse because the first remainder is the lowest place, the ones digit.
Reference table: 0 to 16
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 00000 | 0 | 0 |
| 1 | 00001 | 1 | 1 |
| 2 | 00010 | 2 | 2 |
| 3 | 00011 | 3 | 3 |
| 4 | 00100 | 4 | 4 |
| 5 | 00101 | 5 | 5 |
| 6 | 00110 | 6 | 6 |
| 7 | 00111 | 7 | 7 |
| 8 | 01000 | 10 | 8 |
| 9 | 01001 | 11 | 9 |
| 10 | 01010 | 12 | A |
| 11 | 01011 | 13 | B |
| 12 | 01100 | 14 | C |
| 13 | 01101 | 15 | D |
| 14 | 01110 | 16 | E |
| 15 | 01111 | 17 | F |
| 16 | 10000 | 20 | 10 |
One hex digit matches exactly four bits (a nibble) and one octal digit matches three bits. Converting binary to hex therefore needs no arithmetic: split the bits into groups of four and look each up. For 1011 0101 the groups are B and 5, so the value is B5. To go back, expand each hex digit into four bits.
Why computers use binary
Digital circuits are most reliable when they only have to tell two clearly separated states apart, such as a high or low voltage, so binary is the natural base. Long binary strings are hard for people to read, so addresses, error codes and color values are written in hex, which packs four bits into one character, and Unix file permissions use octal, which packs three. The number 1,000 is 1111101000 in binary (10 digits), 1750 in octal and 3E8 in hex, getting shorter each time.
Powers of two
These values are computed with BigInt when the page is built, so they stay exact even beyond 253.
| Exponent | Decimal | Hex |
|---|---|---|
| 2^0 | 1 | 1 |
| 2^1 | 2 | 2 |
| 2^2 | 4 | 4 |
| 2^3 | 8 | 8 |
| 2^4 | 16 | 10 |
| 2^5 | 32 | 20 |
| 2^6 | 64 | 40 |
| 2^7 | 128 | 80 |
| 2^8 | 256 | 100 |
| 2^10 | 1,024 | 400 |
| 2^12 | 4,096 | 1000 |
| 2^16 | 65,536 | 10000 |
| 2^20 | 1,048,576 | 100000 |
| 2^24 | 16,777,216 | 1000000 |
| 2^31 | 2,147,483,648 | 80000000 |
| 2^32 | 4,294,967,296 | 100000000 |
| 2^53 | 9,007,199,254,740,992 | 20000000000000 |
| 2^63 | 9,223,372,036,854,775,808 | 8000000000000000 |
| 2^64 | 18,446,744,073,709,551,616 | 10000000000000000 |
28 = 256 is the number of values in one byte (0 to 255), and 216 = 65,536 is the number of TCP/UDP port numbers (0 to 65535). 253 matters for JavaScript: ordinary numbers are 64-bit floating-point values and can hold every integer exactly only up to 253 - 1 = 9,007,199,254,740,991. Beyond that some integers cannot be represented, which is why this converter does its arithmetic with BigInt.
How precision, negatives and fractions are handled
- Large integers. Input digits are accumulated in a BigInt, so there is no digit limit built into the tool and results are exact. Very long inputs of thousands of digits can make the browser sluggish.
- Negative numbers. A leading minus sign is accepted in any field. The value is converted as a signed number, so -255 appears as -11111111 in binary and -FF in hex.
- Fractions are not supported. The decimal point is not an accepted character, so a value such as 0.1 is reported as an invalid character. Fractions such as 0.1 repeat forever in binary, which is the root of floating-point rounding errors, but this tool deals with whole numbers only.
- Prefixes. In a field, 0b, 0o and 0x (for binary, octal and hex) are removed automatically, and spaces and underscores are ignored, so 1111_0000 works.
- Working display. The positional expansion is written out for inputs up to 16 digits, and the repeated-division table stops after 40 steps for very long numbers.
Negative numbers and two's complement
Most computers store negative integers in two's complement. In n bits, -x is stored as 2n - x. In 8 bits, -1 is 256 - 1 = 255 = 11111111 (hex FF), -128 is 10000000 (80) and +127 is 01111111 (7F). The same pattern FF means 255 when read as unsigned and -1 when read as signed, so a bit pattern means nothing until you decide its width and signedness. When you enter a negative number above, rows for 8, 16, 32 and 64 bits are listed, and a row is omitted if the value does not fit in that width.
| Width | Signed minimum | Signed maximum | Unsigned maximum |
|---|---|---|---|
| 8 bits | -128 | 127 | 255 |
| 16 bits | -32,768 | 32,767 | 65,535 |
| 32 bits | -2,147,483,648 | 2,147,483,647 | 4,294,967,295 |
| 64 bits | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,615 |
Everyday uses: color codes and chmod
The web color #FF8800 is the red, green and blue bytes FF, 88 and 00 written together. In decimal that is red 255, green 136 and blue 0 (0x88 = 8 x 16 + 8 = 136). A Unix permission such as 755 is read in octal, and each digit is the sum of read = 4, write = 2 and execute = 1.
| Octal | Binary | Permission |
|---|---|---|
| 0 | 000 | --- |
| 1 | 001 | --x |
| 2 | 010 | -w- |
| 3 | 011 | -wx |
| 4 | 100 | r-- |
| 5 | 101 | r-x |
| 6 | 110 | rw- |
| 7 | 111 | rwx |
For example, chmod 755 gives the owner 7 (rwx), the group 5 (r-x) and others 5 (r-x), written rwxr-xr-x and 111 101 101 in binary. chmod 644 is rw-r--r--: only the owner can write, everyone can read.
Checked examples
- Binary to decimal. 10110101 in binary is 128 + 32 + 16 + 4 + 1 = 181, which is B5 in hex (1011 = B, 0101 = 5).
- Hex to decimal. 1F4 in hex is 1 x 256 + 15 x 16 + 4 = 500.
- Octal to binary. 755 in octal is 111 101 101 in binary: expand each octal digit to three bits.
- Base 36. ZZ in base 36 is 35 x 36 + 35 = 1,295. Going the other way, 3,000 divided by 36 gives 83 remainder 12 (C), and 83 divided by 36 gives 2 remainder 11 (B), so 3,000 is 2BC in base 36.
- A large number. 9,007,199,254,740,993 is 20000000000001 in hex. A plain JavaScript number would silently turn it into 9,007,199,254,740,992 (20000000000000 in hex); here BigInt keeps the last digit.
- Two's complement. -100 in 8 bits is 256 - 100 = 156 = 9C. -1 in 32 bits is FFFFFFFF. 200 does not fit in a signed 8-bit value (the range is -128 to 127), so the 8-bit row is hidden and the 16-bit row shows 00C8.
Common mistakes and limits
- Letter case in hex. a to f and A to F are the same digits. Output is shown in capitals.
- Look-alike characters. The digit 0 versus the letter O, and the digit 1 versus the letter l, cause many invalid-input errors. The message names the position of the bad character.
- Digits must fit the base. Binary allows only 0 and 1, octal 0 to 7. Typing 2 into the binary field is rejected.
- Number conversion is not text encoding. This tool changes how a number is written. Turning text into ASCII or Unicode code points is a different task.
- Width must be chosen. Without a stated bit width, a binary string can stand for several different values, as the FF example shows.
Ways to use the result
- Convert a color or memory address to decimal for code, or a decimal value to hex to compare with a debugger.
- When designing a bit mask, enter the value and look at the binary field to see exactly which bits are set.
- For homework and exams, compare your own working with the positional expansion and division steps.
- Short identifiers made of letters and digits, such as URL short codes, are shorter in base 36 than in decimal.
Frequently Asked Questions
Can this convert negative numbers or decimals?
Negative whole numbers work: put a - in front. The 8, 16, 32 and 64-bit two's complement forms are shown too. Numbers with a decimal point are not supported; only integers are handled.
Why does it go all the way up to base 36?
Base 36 uses all of 0 to 9 and A to Z (10 to 35), making it the largest base you can write with only digits and letters. It appears in URL shorteners and short ID schemes, so it is included.
Are very large numbers converted accurately?
Yes. Ordinary JavaScript numbers lose exactness past about 9 x 1015 (253), but this tool calculates with BigInt, so there is no built-in digit limit. Inputs of thousands of digits can make the browser slow.
Can I paste values that start with 0x or 0b?
Yes, in the matching field. 0x (hex), 0b (binary) and 0o (octal) are stripped automatically, and spaces and underscores are ignored, so 1111_0000 is fine.
Why does one hex digit equal four bits?
Because 16 = 24. A hex digit covers 0 to 15, which is exactly the 16 values four bits can hold. By the same reasoning an octal digit corresponds to three bits and a base-32 digit to five.
Why are some bit widths missing from the two's complement table?
A value is shown only for widths that can hold it. For example 200 is outside the signed 8-bit range of -128 to 127, so the table starts at 16 bits.
Related tools
- Color Converter: HEX, RGB and HSL values
- Base64 Encoder & Decoder: another way to write bytes as text
- Roman Numeral Converter: a non-positional number system
- Port Numbers Reference: the 0 to 65535 range in practice
This tool is for learning and development reference. For cryptographic or security-sensitive values, verify with an established library and the official specification.