Number Base Converter
Sooner or later you need to know which three numbers are hiding in #1E90FF, what the 7 and the 5 in chmod 755 actually allow, or why a debugger shows F6 for a variable you know holds -10. All of those questions come down to moving between number bases. Pick binary, octal, decimal, or hexadecimal as the input base, type an integer, and this converter shows the other bases at the same time, with the binary result split into groups of four so each group lines up with one hex digit. The math runs on JavaScript BigInt, so integers dozens of digits long convert without rounding. A few things are worth knowing up front: a 0x, 0o, or 0b prefix that matches the selected base is skipped, as are spaces and underscores between digits; fractions are not accepted; and negative numbers are shown with a minus sign rather than in two's complement. The examples and tables below show how to get two's complement out of it anyway.
Key points
- A prefix that matches the selected tab is skipped: 0xFF in the hex tab reads as FF, 0b1010 in the binary tab as 1010, and 0o755 in the octal tab as 755. Hex letters a–f and prefixes work in either case, and results are always shown in uppercase.
- Enter a negative number with a leading - or the ± button next to the input, and the result keeps its sign: -10 becomes -1010. For 8-bit two's complement, enter 256 − 10 = 246 in decimal and you get 1111 0110 (F6).
- The spaces in the binary result are only there for readability, so you can copy the result and paste it straight back into the binary tab. Spaces are ignored, and so are underscores as in 1111_0110. Switching tabs clears the input.
Integers only (no decimals; for negatives type a leading - or press ±)
Examples
Turning the color #1E90FF into RGB values
A web color written as #RRGGBB is three two-digit hex numbers, one each for the red, green, and blue channels, each running from 0 to 255. In the hexadecimal tab, 1E gives 30, 90 gives 144, and FF gives 255, so #1E90FF is rgb(30, 144, 255), the shade usually called dodger blue. Enter all six digits at once and you get 2,003,199, which is the three channels packed into a single 24-bit integer (30×65,536 + 144×256 + 255), so for color work you need to convert two digits at a time. Going the other way, if a designer hands you rgb(255, 128, 0), enter 255, 128, and 0 in the decimal tab to get FF, 80, and 0, pad the single 0 to 00, and write #FF8000.
Reading chmod 755 and 644 as bits
A Linux permission mode is one octal digit each for the owner, the group, and everyone else, where each digit is the sum of read (4), write (2), and execute (1). Enter 755 in the octal tab and you get binary 1 1110 1101, or 493 in decimal. This tool groups binary in fours, but permissions come in threes, so regroup from the right as 111 101 101. Every 1 is a granted permission, giving rwx r-x r-x: the owner can do everything, while the group and others can read and execute. 644 is 110 100 100 (rw- r-- r--), or 420 in decimal. That decimal value is exactly what you write when a config format such as JSON has no octal notation and expects the mode as a plain number.
Writing -10 in 8-, 16-, and 32-bit two's complement
Enter -10 in the decimal tab and you get binary -1010 and hex -A. That is mathematically correct, but it is not what sits in memory or a register. In a fixed width of n bits, a negative value -x is stored as 2ⁿ − x, so for 8 bits you enter 256 − 10 = 246 in decimal and get 1111 0110, or F6. For 16 bits enter 65,536 − 10 = 65,526 (FFF6), and for 32 bits enter 4,294,967,296 − 10 = 4,294,967,286 (FFFFFFF6). Adding bits only fills the front with 1s, or Fs in hex, while the low digits stay the same. To go backwards, if a dump shows F6 and you know it is a signed 8-bit value, enter F6 in the hex tab, take the 246 it returns, and subtract 256 to read it as -10.
Bases side by side, 0 to 16
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 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 | 1 0000 | 20 | 10 |
Binary is padded with leading zeros to four digits so each row lines up with one hex digit (4 bits). The converter itself drops leading zeros and shows values such as 101 or 1 0000.
Sign notation vs. 8-bit two's complement
| Decimal | This converter's binary | 8-bit two's complement | Hex (8-bit) |
|---|---|---|---|
| 127 | 111 1111 | 0111 1111 | 7F |
| 1 | 1 | 0000 0001 | 01 |
| 0 | 0 | 0000 0000 | 00 |
| -1 | -1 | 1111 1111 | FF |
| -10 | -1010 | 1111 0110 | F6 |
| -100 | -110 0100 | 1001 1100 | 9C |
| -128 | -1000 0000 | 1000 0000 | 80 |
A signed 8-bit integer ranges from -128 to 127. To get the two's complement of -x, enter 256 − x into this converter as a decimal number. Entering 128 gives 1000 0000, which reads as 128 unsigned and as -128 signed.
FAQ
Can I type a prefix like 0xFF or 0b1010?
Yes, as long as it matches the selected tab. The hex tab drops 0x, the octal tab 0o, and the binary tab 0b, in either case, so 0xFF reads as 255 and 0B1010 as 10; for a negative value, put the sign first, as in -0xFF. Prefixes for other bases are not removed. 0x10 in the octal tab fails on the x with 'Not a valid octal number', and in the hex tab b is a legitimate digit worth 11, so 0b1010 is read as hex 0B1010, which is 725,008 in decimal, rather than binary 1010. For a binary value, choose the binary tab first. Leading zeros never change a value, so the old C-style octal literal 0755 can go into the octal tab as is and correctly converts to 493.
Can it convert fractions like 0.625 or 3.14?
Only integers are supported. You can convert the fractional part by hand: multiply it by 2, write down the integer part (0 or 1), and repeat with what is left. For 0.625, ×2 = 1.25 gives 1, 0.25 ×2 = 0.5 gives 0, and 0.5 ×2 = 1 gives 1, so the answer is 0.101. Convert the integer part here, the fraction by this method, and join them. The catch is numbers like 0.1 that never terminate in binary. 0.1 becomes 0.000110011… with 0011 repeating forever, so computers cut it off at some point, and that is why 0.1 + 0.2 is not exactly 0.3 in so many programming languages.
Why do negative numbers get a minus sign instead of a string of 1s?
Because the conversion is mathematical and has no fixed bit width. Two's complement only produces a single answer once you choose a width such as 8 or 32 bits: the same -1 is FF in 8 bits, FFFF in 16, and FFFFFFFF in 32. Picking one of those without knowing your width would mislead more often than it helps, so the converter shows sign and magnitude, as in -1010. When you need two's complement at a particular width, enter 2ⁿ − x in decimal, meaning the absolute value subtracted from 256 for 8 bits, 65,536 for 16, or 4,294,967,296 for 32.
Can I paste values with spaces or separators in them?
Spaces and underscores, yes. Both are ignored wherever they appear, so you can copy a grouped binary result like 1111 0110 straight back into the binary tab, or paste 1111_0110 from source code or DE AD BE EF from a memory dump (3,735,928,559 in decimal). Commas are not ignored, so remove them from a decimal value such as 4,294,967,286, and a period is treated as a decimal point and rejected. Also remember that switching the input tab clears the box, so choose the tab for a copied value's base first and paste afterwards.
How many digits can it handle?
For practical purposes, there is no limit. JavaScript's ordinary Number type stops representing integers exactly beyond 2⁵³ = 9,007,199,254,740,992, so typing 9,007,199,254,740,993 into a typical calculator turns it into …992. This converter uses BigInt and keeps every digit. Enter 2⁶⁴, which is 18,446,744,073,709,551,616, and you get exactly 10000000000000000 in hex: a 1 followed by sixteen zeros.
Why is binary shortened to hex or octal rather than decimal?
Because 16 = 2⁴ and 8 = 2³, one digit maps exactly onto four or three binary digits. 1111 0110 becomes F6 just by reading the first four bits as F and the last four as 6, whereas the decimal 246 tells you nothing about which bits are set until you work it out. Ten is not a power of two, so no such grouping exists. Once the 8-bit byte became standard, hexadecimal, which writes any byte in exactly two digits, took over, and octal survives mostly in Unix file permissions.
Three ways to convert by hand
To go from base n to decimal, add up place values. Counting from the rightmost digit, the places are worth n⁰, n¹, n², and so on, so binary 1011 0110 is 128 + 32 + 16 + 4 + 2 = 182 and hex 2F is 2×16 + 15 = 47. In binary you only add the place values where a 1 appears.
To go from decimal to base n, collect remainders. Dividing 182 by 2 again and again leaves remainders of 0, 1, 1, 0, 1, 1, 0, 1, and reading them in reverse gives 10110110. In hex, 182 ÷ 16 = 11 remainder 6, and 11 is B, so the answer is B6. Keep dividing until the quotient reaches 0 and read the remainders from the bottom up; the same steps work for any base.
Between binary and hex or octal you group instead of dividing. Split from the right into fours and 1011 0110 becomes B6; split into threes and 10 110 110 becomes 266 in octal. If the leftmost group is short, pretend it has leading zeros. To go directly between octal and hex, pass through binary, which is the least error-prone route. Once the 0–15 rows of the table above are second nature, most conversions can be done in your head.
How computers store negative numbers: two's complement
A computer has to fit negative numbers into a fixed number of bits. Using the first bit purely as a sign creates both a +0 and a -0 and complicates the adder, so practically every modern processor uses two's complement instead. To build it, invert every bit and add 1. Ten in 8 bits is 0000 1010; inverted it becomes 1111 0101, and adding 1 gives 1111 0110, which is -10. The result is the same as writing 256 − 10 = 246 in binary, which is why entering 2ⁿ − x is the quickest route with this tool.
An n-bit two's complement value ranges from -2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: -128 to 127 for 8 bits, -32,768 to 32,767 for 16 bits, and -2,147,483,648 to 2,147,483,647 for 32 bits. Go past the top and the value wraps around, so adding 1 to 127 in 8 bits produces 1000 0000, which reads as -128. The bits 1111 0110 are 246 as an unsigned integer and -10 as a signed one; the bits carry no sign of their own, and the data type you read them as decides what they mean.
Widening a value copies its sign bit into the new positions, a step called sign extension. The 8-bit -10 (F6) becomes FFF6 in 16 bits and FFFFFFF6 in 32 bits, and it is the same reason -1 is all Fs at any width. When a debugger or packet dump shows a large value starting with FF, suspect a small negative number before you assume a huge positive one.
Where hex and octal show up in practice
Color codes are where most people meet hex first. #RRGGBB writes 256 levels per channel as two hex digits, for 256³ = 16,777,216 possible colors. The three-digit form #RGB doubles each digit, so #F80 equals #FF8800, and in the eight-digit form #RRGGBBAA the last two digits are opacity. An alpha of 80 is 128 in decimal, or roughly 50 percent opaque.
Permissions and bit masks are the other classic use. Each digit of a chmod mode is a bundle of three on/off switches, and programs that pack several settings into one integer use values with a single bit set, such as 0x01, 0x02, and 0x04. ANDing with a mask like 0xFF00 keeps only the bits you want, so 0x1234 AND 0xFF00 is 0x1200. A subnet mask of 255.255.255.0 is, in binary, 1111 1111 three times followed by 0000 0000, meaning the first 24 bits are the network part, hence /24.
Characters and hardware addresses are written in hex too. Unicode U+AC00 is 44,032 in decimal, the code point of the Korean syllable 가, and the 11,172 precomposed Hangul syllables run from U+AC00 to U+D7A3. A network card's MAC address is 48 bits written as 12 hex digits, and an IPv6 address is 128 bits written as 32.
Sources
Related Calculators
Scientific Calculator
An online scientific calculator for sin, cos, tan and their inverses, log and ln, powers (^), and square roots (√), entered as full expressions. Covers DEG vs RAD, trig values for common angles, reading exponent notation, and the complete list of supported keys.
Calculator
An immediate-execution online calculator that completes each step as soon as you press an operator. Supports + − × ÷, %, ±, and keyboard input, with worked key sequences explaining the % key, how 0.1 + 0.2 is handled, 12-digit rounding, and how large numbers are shown.