Number Base Converter
Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, fractions included. See the two's complement bits and every step of the working.
Use a point for fractions and a minus sign for negatives. Spaces and underscores between digits are ignored.
—
—
—
—
—
Two's complement
Enter a whole number to see its fixed-width bit pattern.
- Bits
- Hex
- Read as signed
- Read as unsigned
Show the working
Why convert between number bases?
Computers store everything in binary, people think in decimal, and programmers lean on hexadecimal and octal as compact shorthand for bits. Converting by hand is slow and error-prone past a few digits. This converter shows a value in binary, octal, decimal and hex at once, plus any base from 2 to 36. It works with exact arbitrary-precision numbers, so long values and fractions convert without rounding, it marks fractions that repeat forever, shows the two's complement bits a processor would store, and can lay out every step of the working for homework.
How it works
- Choose the base your number is written in: binary, octal, decimal, hexadecimal, or any other base from 2 to 36 (bases above 10 use the letters A–Z as digits).
- Type the value. A minus sign, a point for the fractional part, and a matching
0x,0bor0oprefix are all fine; spaces and underscores between digit groups are ignored. - Read all four results as you type, plus the custom base. Digits in parentheses repeat forever. Tick Group digits to split long values into readable blocks.
- For whole numbers, the two's complement panel shows the 8- to 128-bit pattern and reads it as signed and unsigned. Open Show the working for each step.
How number bases work
A number base (or radix) is how many unique digits a system uses to represent values. Decimal, the everyday base 10, uses digits 0–9. Binary (base 2) uses just 0 and 1, which is how computers store everything at the lowest level. Hexadecimal (base 16) packs four binary digits into one, so it's the compact shorthand you see in color codes, memory addresses and byte dumps. Octal (base 8) groups three bits and still shows up in Unix file permissions.
In every base, each digit is multiplied by the base raised to the power of its position, counting from zero on the right. Decimal 156 means 1×100 + 5×10 + 6×1. Binary 10011100 means 128 + 16 + 8 + 4, which is also 156. Bases above ten borrow letters for the extra digits: A is 10, B is 11, and so on up to F (15) in hex and Z (35) in base 36. Positions to the right of the point carry negative powers: in binary, 0.1 is one half, 0.01 one quarter, 0.001 one eighth.
Worked example: converting 156 by hand
Decimal to binary: divide by 2
Divide by 2 repeatedly and write down each remainder. Reading the remainders from the bottom up gives the binary digits.
| Divide | Quotient | Remainder |
|---|---|---|
| 156 ÷ 2 | 78 | 0 |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Bottom to top, the remainders read 10011100.
Binary to hex and octal: group the bits
Because 16 is 2⁴, each hex digit stands for exactly four bits. Split 10011100 into fours from the right, 1001 1100, and convert each group: 1001 is 9 and 1100 is 12, written C. So 156 is 9C in hex. Octal works the same way with groups of three, since 8 is 2³: 10 011 100 becomes 2, 3, 4, so 156 is 234 in octal. If the leftmost group comes up short, pad it with zeros.
Hex to decimal: multiply and add
Going back, multiply each digit by its place value: 9C is 9×16 + 12×1 = 156. A longer value works the same way: 1F4 is 1×256 + 15×16 + 4×1 = 500.
Converting fractions to binary
The fractional part goes the other way: multiply by the new base, take the whole-number part as the next digit, and keep the fraction for the next round. For 0.625 in binary:
| Multiply | Result | Digit |
|---|---|---|
| 0.625 × 2 | 1.25 | 1 |
| 0.25 × 2 | 0.5 | 0 |
| 0.5 × 2 | 1 | 1 |
Top to bottom, the digits read 101, so 0.625 is 0.101. The fraction reached zero, so the binary ends. Try 0.1 and it never does: the fractions run 0.2, 0.4, 0.8, 0.6, 0.2 and the cycle starts again, giving0.0(0011), where the digits in parentheses repeat forever. The rule behind it: a fraction in lowest terms ends in a base only if every prime factor of its denominator divides that base. One tenth has a factor of 5, so it ends in decimal but repeats in binary, octal (0.0(6314)) and hex (0.1(9)); one third repeats in decimal but is exactly 0.1 in base 3. This is why floating-point arithmetic gives 0.1 + 0.2 = 0.30000000000000004: the computer stores the nearest binary fraction it can fit.
Two's complement: how computers store negative numbers
The converter writes −156 as −10011100, the way you would on paper. Hardware has no minus sign; it uses a fixed number of bits, and for signed values the pattern of a negative number −n is 2width − n. The leftmost bit then doubles as the sign: 0 for zero and positives, 1 for negatives. A quick manual method is to write the positive value, flip every bit and add 1. Here are some 8-bit values:
| Value | 8-bit pattern | Hex |
|---|---|---|
| 5 | 00000101 | 05 |
| -5 | 11111011 | FB |
| 127 | 01111111 | 7F |
| -128 | 10000000 | 80 |
| -1 | 11111111 | FF |
The same bits mean different numbers depending on how they're read: 10011100 is 156 as an unsigned byte but −100 as a signed one. An 8-bit signed value runs from −128 to 127, a 16-bit one from −32,768 to 32,767, and a 32-bit one from −2,147,483,648 to 2,147,483,647. Type a bit pattern in binary or hex and the two's complement panel shows both readings, which helps when a value from a register, a packet or a file looks unexpectedly huge.
Where you'll meet each base
- Hexadecimal: web colors (#FF8800 is red 255, green 136, blue 0; the color converter does that split for you), memory addresses, hashes such as the digests from the hash generator, and byte dumps. One byte is always exactly two hex digits.
- Octal: Unix file permissions. In
chmod 755, each digit is three bits for read (4), write (2) and execute (1), so 7 is rwx and 5 is r-x. - Binary: bit flags, masks and network masks; 255.255.255.0 is twenty-four 1s followed by eight 0s.
- Base 36: short IDs and compact URLs, because 0–9 plus a–z give 36 symbols per character.
- 128-bit numbers: a UUID is a 128-bit number written in hex; paste its 32 digits here, or use the UUID decoder to read its fields.
Frequently asked questions
Which number bases are supported?
Any base from 2 to 36, in both directions. Binary (base 2), octal (base 8), decimal (base 10) and hexadecimal (base 16) are at the top of the input menu, with every other base below them, and the result always shows all four common bases at once. A custom output shows the same value in any base from 2 to 36. Bases above 10 use the digits 0–9 followed by the letters A–Z, so base 36 counts up to Z (35).
How do I convert decimal to binary by hand?
Divide the number by 2 and write down the remainder, then divide the quotient by 2 again, and repeat until the quotient is 0. Reading the remainders from the last to the first gives the binary digits: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 is 1101. The same method works for any base; open Show the working to see every step for your own number.
How do I convert binary to hex by hand?
Split the binary number into groups of four bits starting from the right, padding the leftmost group with zeros if needed, then replace each group with its hex digit: 0000 is 0, 1001 is 9, 1010 is A, 1111 is F. For example, 101101 becomes 0010 1101, which is 2D. For octal, use groups of three bits instead.
Can it convert fractions like 0.1 to binary?
Yes. Type a point in any base, such as 0.1 in decimal or ff.8 in hex, and the fractional part is converted exactly. When the result never ends, the digits that repeat are shown in parentheses: 0.1 in decimal is 0.0(0011) in binary, meaning 0.0001100110011… forever. Fractions that neither end nor repeat within 64 digits are cut off with an ellipsis.
Why can't 0.1 be written exactly in binary?
A fraction in lowest terms ends in a base only if every prime factor of its denominator also divides that base. 0.1 is 1/10, and 10 = 2 × 5; the 5 doesn't divide 2, so the binary digits repeat forever. Computers store such numbers rounded to a fixed number of bits, which is why 0.1 + 0.2 is 0.30000000000000004 in JavaScript, Python and most other languages.
How do I find the two's complement of a negative number?
Choose a bit width, then add the negative number to 2 to the power of the width: for −5 in 8 bits, 256 − 5 = 251, which is 11111011. Equivalently, write 5 in binary (00000101), flip every bit (11111010) and add 1 (11111011). The two's complement panel does this for 8 to 128 bits, or picks the smallest width that fits, and also reads a bit pattern you type back as both a signed and an unsigned number.
Does it handle negative numbers?
Yes. Put a minus sign in front of the value (for example -1010 in binary) and the sign is kept across every base, the way you would write it by hand: −13 is −1101 in binary and −D in hex. For the fixed-width bit pattern a processor stores, see the two's complement panel.
How big a number can I convert?
Whole numbers use JavaScript's BigInt, so there's no 32- or 64-bit limit: you can convert numbers up to 100,000 digits long without losing precision, and fractional parts up to 2,000 digits. The values are handled as exact fractions, never as floating point, so nothing is rounded.
What happens if I type an invalid digit?
If a character isn't a valid digit for the base you selected, like the digit 2 in a binary number, the tool names the offending character and the digits that are allowed, instead of guessing.
Can I type a 0x or 0b prefix?
Yes, as long as it matches the selected base: 0x with Hexadecimal, 0b with Binary, 0o with Octal. If the prefix belongs to a different base (0xFF with Decimal selected), the tool tells you which base to pick. In a base where the prefix letter is itself a digit, it's read as digits: 0b in hexadecimal is 0xB = 11. Spaces, underscores and commas between digit groups, as in 1_000_000 or 1010 1010, are ignored, and upper- and lower-case letters are both accepted.
Why is hexadecimal used so much in programming?
Each hex digit maps to exactly four bits, so one byte is always two hex digits and long binary values become short and readable. That's why colors (#FF8800), memory addresses, hashes and byte dumps are written in hex.
Is my input sent anywhere?
No. Everything runs locally in your browser and nothing is uploaded. The last value and your settings are kept in this browser's local storage so they're still there next time.
Related tools
More free, private, browser-based utilities — no upload, no sign-up.