Number Base Converter: Binary, Decimal, Hex and Octal
255 in decimal is 1111 1111 in binary, 377 in octal and FF in hexadecimal. To convert a number to another base, divide it by that base again and again and read the remainders backwards; to go from binary to hex, group the bits in fours and write each group as one hex digit. The converter below does it for whole numbers up to 5,000 digits long in any base from 2 to 36, and can show a number as an 8, 16, 32 or 64-bit two’s-complement value.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
Converted
8 bits, 1 byte, 2 hex digits
- Binary (base 2)
- 1111 1111
- Octal (base 8)
- 377
- Decimal (base 10)
- 255
- Hexadecimal (base 16)
- FF
- Base 36
- 73
Two’s complement
0 to 16 in binary, octal and hexadecimal
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
Powers of two
| Power | Decimal | Hexadecimal | Bits to write it |
|---|---|---|---|
| 2^4 | 16 | 10 | 5 |
| 2^8 | 256 | 100 | 9 |
| 2^10 | 1,024 | 400 | 11 |
| 2^16 | 65,536 | 10000 | 17 |
| 2^20 | 1,048,576 | 100000 | 21 |
| 2^24 | 16,777,216 | 1000000 | 25 |
| 2^31 | 2,147,483,648 | 80000000 | 32 |
| 2^32 | 4,294,967,296 | 100000000 | 33 |
| 2^53 | 9,007,199,254,740,992 | 20000000000000 | 54 |
| 2^63 | 9,223,372,036,854,775,808 | 8000000000000000 | 64 |
| 2^64 | 18,446,744,073,709,551,616 | 10000000000000000 | 65 |
Range of 8, 16, 32 and 64-bit integers
| Width | Signed range | Unsigned maximum | Most negative, in hex | -1, in hex |
|---|---|---|---|---|
| 8-bit | -128 to 127 | 255 | 80 | FF |
| 16-bit | -32,768 to 32,767 | 65,535 | 80 00 | FF FF |
| 32-bit | -2,147,483,648 to 2,147,483,647 | 4,294,967,295 | 80 00 00 00 | FF FF FF FF |
| 64-bit | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 18,446,744,073,709,551,615 | 80 00 00 00 00 00 00 00 | FF FF FF FF FF FF FF FF |
Negative numbers in two’s complement
| Decimal | 8-bit binary | 8-bit hex | 16-bit hex | 32-bit hex |
|---|---|---|---|---|
| -1 | 1111 1111 | FF | FF FF | FF FF FF FF |
| -2 | 1111 1110 | FE | FF FE | FF FF FF FE |
| -5 | 1111 1011 | FB | FF FB | FF FF FF FB |
| -10 | 1111 0110 | F6 | FF F6 | FF FF FF F6 |
| -100 | 1001 1100 | 9C | FF 9C | FF FF FF 9C |
| -127 | 1000 0001 | 81 | FF 81 | FF FF FF 81 |
| -128 | 1000 0000 | 80 | FF 80 | FF FF FF 80 |
| -129 | does not fit | does not fit | FF 7F | FF FF FF 7F |
How to convert between number bases
- Decimal to another base. Divide the number by the base and keep the remainder; divide the quotient again, until it reaches 0. Read the remainders from last to first. For 13 in binary: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 is 1101.
- Another base to decimal. Multiply each digit by the base raised to its position, counting from 0 on the right, and add: binary 1101 = 1×8 + 1×4 + 0×2 + 1×1 = 13.
- Binary to hexadecimal or octal. Group the bits from the right, in fours for hex and threes for octal, and write each group as one digit: 1111 1111 is F and F, so FF; 11 111 111 is 3, 7 and 7, so 377.
- Hexadecimal to binary. Replace each hex digit by its four bits: 3 is 0011 and A is 1010, so 3A is 0011 1010.
- A negative number in two’s complement. Write the size in binary at the chosen width, flip every bit and add 1. For -5 in 8 bits: 5 is 0000 0101, flipped it is 1111 1010, plus 1 gives 1111 1011.
Frequently asked questions
- How do I convert decimal to binary?
- Divide the number by 2 repeatedly and write down each remainder; the remainders read from last to first are the binary digits. 13 becomes 1101, and 255 becomes 1111 1111. Or type the number into the converter and the binary row shows it, with the digits grouped in fours.
- How do I convert binary to hexadecimal?
- Split the bits into groups of four, starting from the right, and write each group as a hex digit (0000 is 0, 1001 is 9, 1010 is A, 1111 is F). 1111 1111 is F and F, so FF. Each hex digit is exactly four bits, which is why programmers use hex as shorthand for binary.
- What is two’s complement?
- Two’s complement is how computers store negative whole numbers. At a fixed width such as 8 bits, -x is stored as 2⁸ − x, which is the same as flipping every bit of x and adding 1. -5 in 8 bits is 1111 1011. The top bit is 1 for every negative number, and adding two numbers works the same as for positive ones, so the hardware needs no separate subtraction.
- Why does FF show as -1 in the two’s-complement view?
- Bits do not carry a sign; the width and the reading do. The 8 bits 1111 1111 are 255 read as unsigned and -1 read as signed two’s complement. Choose 8-bit in the converter and enter FF in base 16 to see both readings side by side. A value that is too big for the chosen width, like 256 in 8 bits, is reported as not fitting.
- How big a number can it convert?
- Up to 5,000 digits in the base you type. The converter uses arbitrary-precision integers (JavaScript BigInt), so nothing is rounded: a 64-bit or 256-bit value, or a number with a thousand digits, converts exactly. Ordinary calculators and code that use floating-point numbers lose exactness above 2^53, which is about 9 quadrillion.
- Can it convert fractions or negative numbers?
- Negative whole numbers, yes: type a minus sign, and every row shows the number with its sign (the two’s-complement view shows how a computer would store it). Fractions and decimals like 0.1 are not supported: only whole numbers convert, and the converter tells you when it sees a decimal point.
- What do the prefixes 0x, 0b and 0o mean?
- They mark the base in most programming languages: 0x for hexadecimal, 0b for binary and 0o for octal, so 0xFF, 0b11111111 and 0o377 are all 255. You can type the prefix that matches the base you chose, and the “Show 0b, 0o and 0x prefixes” option adds them to the results. Octal in older code is written with just a leading 0 (0377), which this converter reads as plain digits.
- Which bases can I use, and what digits do they have?
- Any base from 2 to 36. Bases up to 10 use the digits 0 to base − 1; larger bases continue with letters, A for 10, B for 11, up to Z for 35. Typing is not case-sensitive. Common choices are 2 (binary), 8 (octal), 10 (decimal), 16 (hexadecimal), 32 and 36, often used for short codes and IDs.
How it works
The number you type is checked digit by digit against the base you chose, then read into an exact whole number (a JavaScript BigInt), and written out in each base with the standard radix algorithm; nothing goes through floating point, so the result is exact at any size. Spaces and underscores between digits are ignored, and so are thousands commas in decimal; a minus sign, and the prefix that matches the base (0x, 0b, 0o), are accepted. Digit grouping is display only: “Automatic” groups binary in fours (nibbles), hex in twos (bytes), and octal and decimal in threes, and Copy always gives the digits without separators. The two’s-complement view takes the width you choose (8, 16, 32 or 64 bits): a value from −2^(n−1) to 2^(n−1) − 1 is stored as itself when zero or positive and as 2^n plus itself when negative; a value that only fits as unsigned (up to 2^n − 1) is shown as the pattern it is with its signed reading, and anything else is reported as not fitting. Everything runs in your browser, and nothing you type is sent anywhere.
Sources
More free tools
- Scientific Notation ConverterConvert any number to scientific, E and engineering notation or back to standard form, round to significant figures, and count the sig figs you typed.
- Chmod CalculatorConvert Unix file permissions between a checkbox grid, octal (755, 4755), ls -l text (rwxr-xr-x) and chmod commands; apply changes like u+x,go-w.
- IP Subnet CalculatorWork out the network, broadcast, usable hosts, masks and binary of any IPv4 CIDR block, split it into subnets, and expand or compress IPv6 addresses.
- Roman Numeral ConverterConvert numbers and years to Roman numerals and back, 1 to 3,999 (larger with a bar). Strict checking explains why IIII, VX or IC are not valid.
- Number to Words ConverterConvert numbers to English words, check amounts and ordinals, or words back to digits. Exact up to 66 digits, with optional British “and”.
- Text to Binary ConverterConvert text to binary, hex, octal or decimal bytes and back. UTF-8 by default (é is 2 bytes, an emoji 4) or UTF-16, with a per-character breakdown.