Binary, Hex & Decimal Converter
Type a number in any box and the others change as you type: binary, octal, decimal and hex, with the working shown. Switch to Advanced for any base up to 36, fractions, two’s complement, bitwise maths, text to binary and a bit grid you can click.
Prefixes like 0b, 0o and 0x, spaces and underscores are fine. Use a minus sign for negatives and a point for fractions, like 1010.101.
Uses the whole-number part of the number in the boxes above. Type a negative number like −5 to see how it is stored.
Click a bit to flip it. The boxes above change too. Bit 0 is on the right.
Type in either box. Bytes can be typed with spaces or commas between them, or run together for binary (8 digits each) and hex (2 each).
Codes 0 to 127. The row for the whole number in the boxes above is highlighted when it is in this range.
| Dec | Hex | Binary | Octal | Character |
|---|---|---|---|---|
| 0 | 00 | 00000000 | 000 | NUL |
| 1 | 01 | 00000001 | 001 | SOH |
| 2 | 02 | 00000010 | 002 | STX |
| 3 | 03 | 00000011 | 003 | ETX |
| 4 | 04 | 00000100 | 004 | EOT |
| 5 | 05 | 00000101 | 005 | ENQ |
| 6 | 06 | 00000110 | 006 | ACK |
| 7 | 07 | 00000111 | 007 | BEL |
| 8 | 08 | 00001000 | 010 | BS |
| 9 | 09 | 00001001 | 011 | TAB |
| 10 | 0A | 00001010 | 012 | LF |
| 11 | 0B | 00001011 | 013 | VT |
| 12 | 0C | 00001100 | 014 | FF |
| 13 | 0D | 00001101 | 015 | CR |
| 14 | 0E | 00001110 | 016 | SO |
| 15 | 0F | 00001111 | 017 | SI |
| 16 | 10 | 00010000 | 020 | DLE |
| 17 | 11 | 00010001 | 021 | DC1 |
| 18 | 12 | 00010010 | 022 | DC2 |
| 19 | 13 | 00010011 | 023 | DC3 |
| 20 | 14 | 00010100 | 024 | DC4 |
| 21 | 15 | 00010101 | 025 | NAK |
| 22 | 16 | 00010110 | 026 | SYN |
| 23 | 17 | 00010111 | 027 | ETB |
| 24 | 18 | 00011000 | 030 | CAN |
| 25 | 19 | 00011001 | 031 | EM |
| 26 | 1A | 00011010 | 032 | SUB |
| 27 | 1B | 00011011 | 033 | ESC |
| 28 | 1C | 00011100 | 034 | FS |
| 29 | 1D | 00011101 | 035 | GS |
| 30 | 1E | 00011110 | 036 | RS |
| 31 | 1F | 00011111 | 037 | US |
| 32 | 20 | 00100000 | 040 | Space |
| 33 | 21 | 00100001 | 041 | ! |
| 34 | 22 | 00100010 | 042 | " |
| 35 | 23 | 00100011 | 043 | # |
| 36 | 24 | 00100100 | 044 | $ |
| 37 | 25 | 00100101 | 045 | % |
| 38 | 26 | 00100110 | 046 | & |
| 39 | 27 | 00100111 | 047 | ' |
| 40 | 28 | 00101000 | 050 | ( |
| 41 | 29 | 00101001 | 051 | ) |
| 42 | 2A | 00101010 | 052 | * |
| 43 | 2B | 00101011 | 053 | + |
| 44 | 2C | 00101100 | 054 | , |
| 45 | 2D | 00101101 | 055 | - |
| 46 | 2E | 00101110 | 056 | . |
| 47 | 2F | 00101111 | 057 | / |
| 48 | 30 | 00110000 | 060 | 0 |
| 49 | 31 | 00110001 | 061 | 1 |
| 50 | 32 | 00110010 | 062 | 2 |
| 51 | 33 | 00110011 | 063 | 3 |
| 52 | 34 | 00110100 | 064 | 4 |
| 53 | 35 | 00110101 | 065 | 5 |
| 54 | 36 | 00110110 | 066 | 6 |
| 55 | 37 | 00110111 | 067 | 7 |
| 56 | 38 | 00111000 | 070 | 8 |
| 57 | 39 | 00111001 | 071 | 9 |
| 58 | 3A | 00111010 | 072 | : |
| 59 | 3B | 00111011 | 073 | ; |
| 60 | 3C | 00111100 | 074 | < |
| 61 | 3D | 00111101 | 075 | = |
| 62 | 3E | 00111110 | 076 | > |
| 63 | 3F | 00111111 | 077 | ? |
| 64 | 40 | 01000000 | 100 | @ |
| 65 | 41 | 01000001 | 101 | A |
| 66 | 42 | 01000010 | 102 | B |
| 67 | 43 | 01000011 | 103 | C |
| 68 | 44 | 01000100 | 104 | D |
| 69 | 45 | 01000101 | 105 | E |
| 70 | 46 | 01000110 | 106 | F |
| 71 | 47 | 01000111 | 107 | G |
| 72 | 48 | 01001000 | 110 | H |
| 73 | 49 | 01001001 | 111 | I |
| 74 | 4A | 01001010 | 112 | J |
| 75 | 4B | 01001011 | 113 | K |
| 76 | 4C | 01001100 | 114 | L |
| 77 | 4D | 01001101 | 115 | M |
| 78 | 4E | 01001110 | 116 | N |
| 79 | 4F | 01001111 | 117 | O |
| 80 | 50 | 01010000 | 120 | P |
| 81 | 51 | 01010001 | 121 | Q |
| 82 | 52 | 01010010 | 122 | R |
| 83 | 53 | 01010011 | 123 | S |
| 84 | 54 | 01010100 | 124 | T |
| 85 | 55 | 01010101 | 125 | U |
| 86 | 56 | 01010110 | 126 | V |
| 87 | 57 | 01010111 | 127 | W |
| 88 | 58 | 01011000 | 130 | X |
| 89 | 59 | 01011001 | 131 | Y |
| 90 | 5A | 01011010 | 132 | Z |
| 91 | 5B | 01011011 | 133 | [ |
| 92 | 5C | 01011100 | 134 | \ |
| 93 | 5D | 01011101 | 135 | ] |
| 94 | 5E | 01011110 | 136 | ^ |
| 95 | 5F | 01011111 | 137 | _ |
| 96 | 60 | 01100000 | 140 | ` |
| 97 | 61 | 01100001 | 141 | a |
| 98 | 62 | 01100010 | 142 | b |
| 99 | 63 | 01100011 | 143 | c |
| 100 | 64 | 01100100 | 144 | d |
| 101 | 65 | 01100101 | 145 | e |
| 102 | 66 | 01100110 | 146 | f |
| 103 | 67 | 01100111 | 147 | g |
| 104 | 68 | 01101000 | 150 | h |
| 105 | 69 | 01101001 | 151 | i |
| 106 | 6A | 01101010 | 152 | j |
| 107 | 6B | 01101011 | 153 | k |
| 108 | 6C | 01101100 | 154 | l |
| 109 | 6D | 01101101 | 155 | m |
| 110 | 6E | 01101110 | 156 | n |
| 111 | 6F | 01101111 | 157 | o |
| 112 | 70 | 01110000 | 160 | p |
| 113 | 71 | 01110001 | 161 | q |
| 114 | 72 | 01110010 | 162 | r |
| 115 | 73 | 01110011 | 163 | s |
| 116 | 74 | 01110100 | 164 | t |
| 117 | 75 | 01110101 | 165 | u |
| 118 | 76 | 01110110 | 166 | v |
| 119 | 77 | 01110111 | 167 | w |
| 120 | 78 | 01111000 | 170 | x |
| 121 | 79 | 01111001 | 171 | y |
| 122 | 7A | 01111010 | 172 | z |
| 123 | 7B | 01111011 | 173 | { |
| 124 | 7C | 01111100 | 174 | | |
| 125 | 7D | 01111101 | 175 | } |
| 126 | 7E | 01111110 | 176 | ~ |
| 127 | 7F | 01111111 | 177 | DEL |
How your number is converted
Your number, step by step: divide by 2, read the remainders, then group the bits into hex.
- 1
Divide by 2
173 ÷ 2 = 86 r 1
8 divisions - 2
Read remainders up
binary 1010 1101
- 3
Fours make hex
1010 1101
hex AD - 4
Check place values
128+32+8+4+1
= 173
Read more: the formula, a worked example, two’s complement and tables
Every number system works the same way: each place is worth the base times the place to its right. In decimal the places are 1, 10, 100, 1000. In binary (base 2) they are 1, 2, 4, 8, 16. In hex (base 16) they are 1, 16, 256, 4096, and the digits run 0–9 then A–F for 10 to 15. Octal (base 8) uses the digits 0–7. Computers store everything as bits (0s and 1s); hex and octal are short ways to write those bits, because one hex digit is exactly four bits and one octal digit is exactly three.
The formula
To base b: divide by b, write down the remainder, repeat with the answer until it is 0; the digits are the remainders read from last to first
From base b: value = (each digit × b to the power of its place), added up; places count 0, 1, 2… from the right of the point, and −1, −2… after it
Fraction part to base b: multiply by b; the whole part is the next digit; repeat with what is left
Binary ↔ hex: 4 bits = 1 hex digit. Binary ↔ octal: 3 bits = 1 octal digit
Two’s complement of −x in n bits = 2ⁿ − x (flip every bit of x, then add 1)
Worked example
173 to binary. Divide by 2 and keep the remainders: 173 ÷ 2 = 86 r 1, 86 ÷ 2 = 43 r 0, 43 ÷ 2 = 21 r 1, 21 ÷ 2 = 10 r 1, 10 ÷ 2 = 5 r 0, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1. Read from the last remainder to the first: 10101101.
Check with place values. 10101101 has 1s in the 128, 32, 8, 4 and 1 places: 128 + 32 + 8 + 4 + 1 = 173.
To hex. Split into fours: 1010 1101. 1010 = 8 + 2 = 10 = A and 1101 = 8 + 4 + 1 = 13 = D, so 173 = AD in hex. Check: 10 × 16 + 13 = 160 + 13 = 173.
To octal. Split into threes from the right: 010 101 101 = 2, 5, 5, so 173 = 255 in octal. Check: 2 × 64 + 5 × 8 + 5 = 128 + 40 + 5 = 173.
Fractions
10.625 to binary: the whole part 10 is 1010. For the fraction part, multiply by 2 and take the whole part each time: 0.625 × 2 = 1.25 → 1, 0.25 × 2 = 0.5 → 0, 0.5 × 2 = 1.0 → 1, and nothing is left. So 10.625 = 1010.101. Going back: 8 + 2 + 0.5 + 0.125 = 10.625. Some fractions never end in another base: 0.1 in binary is 0.0001100110011… with 0011 repeating for ever, which is why computers cannot store 0.1 exactly. The converter stops at the number of digits you choose, shows … when it has cut a number short, and names the repeating block.
Negative numbers: two’s complement
Computers store negative whole numbers in two’s complement. To write −5 in 8 bits: 5 is 00000101, flip every bit to get 11111010, then add 1 to get 11111011 (FB in hex). This is the same as 2⁸ − 5 = 256 − 5 = 251. The left-most bit is the sign bit: 1 means negative. Read 11111011 as unsigned and it is 251; read it as signed and it is −5. If a number is too big for the word size it overflows: in 8 bits, 200 read as signed is 200 − 256 = −56.
| Word size | Signed range | Unsigned range |
|---|---|---|
| 8 bits (byte) | −128 to 127 | 0 to 255 |
| 16 bits | −32,768 to 32,767 | 0 to 65,535 |
| 32 bits | −2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
| 64 bits | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
Bitwise operations
- AND gives 1 only where both bits are 1: 1100 AND 1010 = 1000 (12 AND 10 = 8).
- OR gives 1 where either bit is 1: 1100 OR 1010 = 1110 (14). XOR gives 1 where the bits differ: 0110 (6).
- NOT flips every bit in the word size: NOT 00001100 = 11110011 (243 in 8 bits). NAND, NOR and XNOR are NOT of AND, OR and XOR.
- Shift left by k doubles the number k times, dropping bits that fall off the left. Shift right halves it, dropping bits off the right. An arithmetic right shift copies the sign bit in, so negative numbers stay negative. Rotate moves the bits that fall off one end back in at the other.
Hex digits and their bits
| Hex | Binary | Decimal | Hex | Binary | Decimal |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
Powers of 2
| Power | Value | Power | Value |
|---|---|---|---|
| 20 | 1 | 28 | 256 |
| 21 | 2 | 29 | 512 |
| 22 | 4 | 210 | 1,024 |
| 23 | 8 | 211 | 2,048 |
| 24 | 16 | 212 | 4,096 |
| 25 | 32 | 213 | 8,192 |
| 26 | 64 | 214 | 16,384 |
| 27 | 128 | 215 | 32,768 |
| 232 | 4,294,967,296 | 264 | 18,446,744,073,709,551,616 |
Text to binary
Text is stored as bytes. This page uses UTF-8, the encoding used by almost every web page. English letters, digits and common symbols (the ASCII set, codes 0–127) take one byte each, so “Hi” is 72 105, or 01001000 01101001 in binary. Accented letters take two bytes, the euro sign € takes three (E2 82 AC) and most emoji take four.
All maths is exact: the converter uses whole numbers of any size (up to 4,000 characters per box) and exact fractions, so there are no rounding errors until a fraction is cut short at the number of digits you choose.
Common questions
How do I convert decimal to binary?
Divide the number by 2 and write down the remainder (0 or 1). Divide the answer by 2 again and keep going until you reach 0. Read the remainders from the last one to the first. For 173: 173 ÷ 2 = 86 r 1, 86 ÷ 2 = 43 r 0 and so on, which gives 10101101.
How do I convert binary to decimal?
Each place in a binary number is worth twice the place to its right: 1, 2, 4, 8, 16 and so on. Add up the places that hold a 1. For 10101101 that is 128 + 32 + 8 + 4 + 1 = 173.
How do I convert hex to decimal?
Hex digits run 0–9 then A = 10, B = 11, up to F = 15, and each place is worth 16 times the place to its right. Multiply each digit by its place value and add: AD = 10 × 16 + 13 × 1 = 173.
How do I convert binary to hex?
Split the bits into groups of four, starting from the right, and add zeros on the left if needed. Each group of four is one hex digit: 1010 = A and 1101 = D, so 10101101 is AD. For octal, use groups of three instead: 010 101 101 = 255.
What is two’s complement?
It is how computers store negative whole numbers. To write −x in n bits, write x in binary, flip every bit and add 1. In 8 bits, 5 is 00000101, flipped it is 11111010, and adding 1 gives 11111011 for −5. An 8-bit signed number runs from −128 to 127.
How do I convert text to binary?
Each character is turned into bytes (UTF-8), and each byte is written as 8 bits. “Hi” is the bytes 72 and 105, which are 01001000 01101001 in binary or 48 69 in hex. Plain English letters take one byte each; a character like € takes three bytes (E2 82 AC).
Related calculators
Made by Zulu Calculator, part of AlphaZulu LLC. Formulas are shown in full and rule figures are checked against official sources; see how we build calculators.