Skip to content

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.

Any base, fractions, signed, bitwise, text, bit grid

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.

Group digits
Between groups
Prefixes (0b, 0o, 0x)
Hex letters
Digits after the point
ResultUpdates as you type—Bits needed—Bytes—Number of 1 bits—Smallest type it fitsWorking
    More tools
    Word size

    Uses the whole-number part of the number in the boxes above. Type a negative number like −5 to see how it is stored.

    —Two’s complement (binary)—Two’s complement (hex)—These bits read as signed—These bits read as unsigned—Signed range—Unsigned range—One’s complement—Sign and magnitude

      How your number is converted

      Your number, step by step: divide by 2, read the remainders, then group the bits into hex.

      1. 1

        Divide by 2

        173 ÷ 2 = 86 r 1
        8 divisions

      2. 2

        Read remainders up

        binary 1010 1101

      3. 3

        Fours make hex

        1010 1101
        hex AD

      4. 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 sizeSigned rangeUnsigned range
      8 bits (byte)−128 to 1270 to 255
      16 bits−32,768 to 32,7670 to 65,535
      32 bits−2,147,483,648 to 2,147,483,6470 to 4,294,967,295
      64 bits−9,223,372,036,854,775,808 to 9,223,372,036,854,775,8070 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

      HexBinaryDecimalHexBinaryDecimal
      000000810008
      100011910019
      200102A101010
      300113B101111
      401004C110012
      501015D110113
      601106E111014
      701117F111115

      Powers of 2

      PowerValuePowerValue
      20128256
      21229512
      2242101,024
      2382112,048
      24162124,096
      25322138,192
      266421416,384
      2712821532,768
      2324,294,967,29626418,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

      Scientific calculatorTrig, logs, powers, roots, factorials, nCr and nPr, memory and history, with degrees, radians or gradians and answers as fractions.Roman numeral converterNumbers to Roman numerals and back, with the reason when a numeral is wrong, dates for tattoos, big numbers with a line over and Roman sums.Fraction calculatorAdd, subtract, multiply, divide and simplify fractions, with steps.Unit converterLength, weight, temperature, volume, area, speed, time, pressure, energy, data, fuel economy and more.

      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.

      Embed this calculator on your site

      Free to use on your website or blog. Paste this code where you want the calculator to appear. Please keep the credit link.

      Binary & hex converter by Zulu Calculator ↗