Skip to main content
ponderloop

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

Whole numbers only. Spaces, underscores, a minus sign and a 0x, 0b or 0o prefix are fine to type.

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

0 to 16 in binary, octal and hexadecimal

Hex needs six extra digits: A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.
DecimalBinaryOctalHexadecimal
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010

Powers of two

Each extra bit doubles the largest number you can hold; a number of n bits is at most 2ⁿ − 1.
PowerDecimalHexadecimalBits to write it
2^416105
2^82561009
2^101,02440011
2^1665,5361000017
2^201,048,57610000021
2^2416,777,216100000025
2^312,147,483,6488000000032
2^324,294,967,29610000000033
2^539,007,199,254,740,9922000000000000054
2^639,223,372,036,854,775,808800000000000000064
2^6418,446,744,073,709,551,6161000000000000000065

Range of 8, 16, 32 and 64-bit integers

Signed integers use two’s complement: the top bit is the sign, and the most negative number has no positive twin.
WidthSigned rangeUnsigned maximumMost negative, in hex-1, in hex
8-bit-128 to 12725580FF
16-bit-32,768 to 32,76765,53580 00FF FF
32-bit-2,147,483,648 to 2,147,483,6474,294,967,29580 00 00 00FF FF FF FF
64-bit-9,223,372,036,854,775,808 to 9,223,372,036,854,775,80718,446,744,073,709,551,61580 00 00 00 00 00 00 00FF FF FF FF FF FF FF FF

Negative numbers in two’s complement

The bits of a negative number are 2ⁿ minus its size. “Does not fit” means the number needs more bits.
Decimal8-bit binary8-bit hex16-bit hex32-bit hex
-11111 1111FFFF FFFF FF FF FF
-21111 1110FEFF FEFF FF FF FE
-51111 1011FBFF FBFF FF FF FB
-101111 0110F6FF F6FF FF FF F6
-1001001 11009CFF 9CFF FF FF 9C
-1271000 000181FF 81FF FF FF 81
-1281000 000080FF 80FF FF FF 80
-129does not fitdoes not fitFF 7FFF FF FF 7F

How to convert between number bases

  1. 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.
  2. 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.
  3. 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.
  4. Hexadecimal to binary. Replace each hex digit by its four bits: 3 is 0011 and A is 1010, so 3A is 0011 1010.
  5. 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

All toolsHome & DIY calculators