Base Converter
Type in any field to convert between bases 2, 8, 10, 16, and any base from 2 to 36, with big numbers, negatives, repeating fractions, and two's complement.
An overline marks the repeating digits. Non-repeating or repeating parts longer than 64 digits are cut off with “…”.
Two's complement
How to Use
- Type a number into any field and the others update instantly: there's one field each for binary, octal, decimal, and hexadecimal, plus a field for any base from 2 to 36.
- Input is case-insensitive. You can include a 0b, 0o, or 0x prefix (it must match the field's base) and separate digits with underscores or spaces, such as 0xFF_FF or 1111 0000, so you can paste numbers straight from code.
- Write negative numbers with a minus sign, like -FF. Integers use BigInt, so 64-bit IDs, hash values, and even larger numbers stay exact.
- Fractions work too. When a fraction doesn't terminate, the repeating digits are marked with an overline—decimal 0.1 is 0.00̅0̅1̅1̅ in binary. Non-repeating or repeating parts longer than 64 digits are cut off with “…”. You can paste an overlined repeating fraction back into any field for an exact conversion.
- The two's complement section offers 8, 16, 32, and 64 bits and shows padded binary and hex. You can also paste hex from a debugger straight into a two's complement field—8-bit FF shows −1 everywhere else. Values outside that width's signed range show an error instead of being silently truncated, and the section is disabled for fractions.
- If something's wrong, only the field with the problem shows the character position and reason, while the other fields keep their last good values. “Select the problem” highlights that character. “Clear” empties every field.
Where base conversion shows up in everyday work
Converting between number bases sounds like a classroom exercise, but developers, sysadmins, and designers run into it constantly:
- CSS colors: a hex color like #FF8800 is three hexadecimal pairs for red, green, and blue. FF is 255, 88 is 136, and 00 is 0, so the same orange written in decimal is rgb(255, 136, 0).
- Unix file permissions: each digit of chmod 755 is an octal digit that maps to exactly three bits for read, write, and execute. 7 is 111, so everything is allowed, and 5 is 101, so read and execute are allowed but write is not. That is why 755 means the owner can do everything while everyone else can read and run the file.
- Network addresses: every part of an IPv4 address is a number from 0 to 255, which is exactly one byte. 192.168.1.1 is C0.A8.01.01 in hexadecimal, and MAC addresses are written in hex to begin with.
- Debuggers and crash dumps: memory addresses, error codes, and register values are normally shown in hex, so you convert whenever a spec or a log file uses a different base.
- Flags and bit masks: when each bit of an integer is an on/off switch, binary is the only way to see which switches are set.
- Coursework and exams: intro computer science, digital logic, and embedded systems classes all include binary, octal, hex, and two’s complement exercises, and certification tests repeat them.
Converting a base only changes how a number is written. The value stays the same, and nothing is hidden, so it is not encryption. It is also a different job from Base64, which encodes arbitrary bytes as text. If you need to turn a file or an image into text, use a Base64 tool instead.
A classic programmer joke makes the point: why do programmers confuse Halloween and Christmas? Because Oct 31 equals Dec 25. Read 31 as an octal number and you get 3 × 8 + 1, which is 25.
A reference table for the first seventeen numbers
If you memorize these rows, most everyday conversions become mental arithmetic:
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 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 | 10000 | 20 | 10 |
The pattern is regular. One hexadecimal digit always matches four binary digits, and one octal digit always matches three. A byte has eight bits, so it needs exactly two hex digits, and the largest byte value, FF, is 255. That is why hex is the standard way to write bytes: it is compact, and you can still see the bits underneath.
A few useful landmarks: 255 is FF and 11111111 in binary and 377 in octal. 256 is 100 in hex. 1024 is 400 in hex, and it is 10000000000 in binary, which is a one followed by ten zeros.
Converting by hand
Decimal to another base: divide repeatedly and read the remainders from the bottom up. To write 100 in binary, divide by 2 again and again: 100 gives 50 remainder 0, 50 gives 25 remainder 0, 25 gives 12 remainder 1, 12 gives 6 remainder 0, 6 gives 3 remainder 0, 3 gives 1 remainder 1, and 1 gives 0 remainder 1. Reading the remainders from last to first gives 1100100.
Another base to decimal: multiply each digit by its place value and add. In binary 1100100, the place values from the right are 1, 2, 4, 8, 16, 32, and 64. The ones sit at 4, 32, and 64, which add up to 100. Hexadecimal works the same way, with place values of 1, 16, 256, and so on.
Binary and hex convert directly without passing through decimal. Split the bits into groups of four, starting from the right, and replace each group with one hex digit. For example, 1101 0110 1111 splits into 1101, 0110, and 1111, which are D, 6, and F, so the result is D6F, or 3439 in decimal. Going the other way, expand each hex digit into four bits. Octal uses the same trick with groups of three.
Signed ranges at each bit width
The two’s complement section lets you choose 8, 16, 32, or 64 bits. The width decides which numbers fit, and the table below lists the signed range for each width along with the hex form of −1:
| Bit width | Minimum | Maximum | −1 in hex |
|---|---|---|---|
| 8 | −128 | 127 | FF |
| 16 | −32768 | 32767 | FFFF |
| 32 | −2147483648 | 2147483647 | FFFFFFFF |
| 64 | −9223372036854775808 | 9223372036854775807 | FFFFFFFFFFFFFFFF |
At every width, −1 is all ones, which is a quick way to recognize a two’s complement value in a dump.
To work out a negative number by hand, invert the bits and add one. For −5 in 8 bits, start with 5, which is 0000 0101, flip every bit to get 1111 1010, and add one to get 1111 1011, or FB. An equivalent shortcut is to subtract the absolute value from two to the power of the width: 256 − 5 is 251, and 251 is FB in hex.
Why some fractions never finish
Whole numbers always convert to a finite string in any base, but fractions do not. Beyond the well-known 0.1, a few examples build intuition:
- 0.5, 0.75, and 0.625 are finite in binary: 0.1, 0.11, and 0.101. Their denominators of 2, 4, and 8 are all powers of 2.
- One third repeats forever in decimal as 0.333 and so on, but in base 3 the very same number is simply 0.1.
- So a repeating fraction is not a property of the number alone. It comes from pairing a number with a base, and a different base can make an endless fraction end.
You can see this in the tool by typing 0.3 with an overline over the 3 into the decimal field, then setting the custom field to base 3. The overline is a Unicode combining character, and you can copy it straight from the tool’s own output.
What this tool does and does not cover
- The custom field accepts bases from 2 to 36 only. There is no base 60 or anything larger.
- The two’s complement section offers four widths, 8, 16, 32, and 64 bits, and only represents integers. It does not show IEEE 754 floating point, and there are no bitwise operators or shifts.
- If the non-repeating part or the repeating block of a fraction runs past 64 digits, the result is cut off with an ellipsis. A truncated result is incomplete, so it cannot be pasted back in for conversion. You get an error instead of a quietly rounded answer.
- The two’s complement fields do not accept a minus sign or a decimal point. Enter negative numbers in the decimal field or another base field, and the padded result appears in the two’s complement fields.
- When a character is not a valid digit for the base, only the affected field reports the position, and the other fields keep their last good values.
When your goal is to turn bytes, files, or images into text for transport, a Base64 tool is the right choice. This converter only deals with how a number itself is written.
FAQ
Why doesn't 0.1 convert to a finite binary fraction?
A fraction terminates in a given base only if every prime factor of its reduced denominator divides that base. 0.1 is 1/10, whose denominator has the factors 2 and 5, but binary only has 2, so the 5 never divides out and you get the repeating fraction 0.00̅0̅1̅1̅. That's also why 0.1 + 0.2 isn't exactly 0.3 in most programming languages. This tool works with exact fractions of whole numbers, so it finds the full repeating block instead of showing a rounded approximation.
What is two's complement, and why is FF equal to −1 in 8 bits?
Two's complement is how computers usually store signed integers: the top bit counts as negative 2 to the power of (bits − 1), and the remaining bits add up as usual. In 8 bits, FF is 1111 1111, which is −128 + 127 = −1, and 80 is 1000 0000, which is −128. The same bits mean different numbers at different widths: FF is −1 in 8 bits but 255 in 16 bits. Two's complement only covers integers, so the section is disabled when you enter a fraction.
Why doesn't it just truncate numbers that don't fit the bit width?
Many languages silently drop the high bits on overflow—storing 300 in 8 bits gives 44—and that's a classic source of hard-to-find bugs. This tool shows an error when a value is outside the signed range of the selected width and tells you that range, such as −128 to 127 for 8 bits, so you know you need a wider type instead of getting a plausible-looking wrong answer.
How large a number can it convert? Will it lose precision?
Integers use BigInt, so there's no fixed limit and numbers beyond 2⁵³ or 2⁶⁴ stay exact to the last digit. Converters built on regular JavaScript numbers start losing precision past 2⁵³ (about 9 quadrillion), which breaks 64-bit IDs and hash values. Fractions use exact ratios of BigInts, so there are no floating-point errors either.
What are base 36 and other custom bases used for?
Bases above 10 use letters for digit values of 10 and up—A is 10 and Z is 35—so the largest base is 36. Base 36 is popular for short URLs, order numbers, and codes that need to pack a large number into few characters. Bases like 3, 5, 7, and 12 show up in math and computer science homework.
Related Tools
Text to Binary & Hex Converter
Type in either box to turn text into the binary, octal, decimal, and hex of each UTF-8 byte, or decode those bytes back into text.
Unicode Escape Encoder & Decoder
Type in either box to turn text into \uXXXX, \u{…}, &#x…;, or U+XXXX, or decode any mix of Unicode escapes back into text.
Base64 Encoder & Decoder
Type in either box to encode text as Base64 or decode Base64 back into text. UTF-8 safe, with a URL-safe alphabet option.
URL Encoder & Decoder
Type in either box to percent-encode text for a URL, or decode %20-style sequences back into readable text.
HTML Entity Encoder & Decoder
Type in either box to turn text into HTML entities, or decode < & 中 and other entities back into text. All named entities supported.
Unit Converter
Convert length, weight, area, volume, temperature, speed, and data size, including stones and US and imperial pints.