Ultra Calculator
    Maths

    Binary, Decimal and Hex Converter

    To turn decimal into binary, divide by 2 repeatedly and read the remainders from last to first: 13 becomes 1101. To go back, add each digit times its place value: 8 + 4 + 0 + 1 = 13. Enter a whole number, then choose the base it is in and the base you want.

    Last updated by Ultra Calculator

    Binary, Decimal and Hex

    How to calculate it

    N = dₖ × b^k + ... + d₁ × b^1 + d₀ × b^0
    N
    the value of the number in decimal
    b
    the base the number is written in, such as 2 or 16
    dₖ ... d₀
    the digits from left to right, where A = 10, B = 11 and so on up to Z = 35
    k
    the position of the leftmost digit, counting from 0 at the right

    To convert from decimal to base b, divide by b repeatedly and read the remainders from last to first. Each hex digit represents 4 binary digits, and each octal digit represents 3.

    Worked example

    255 in binary

    Decimal 255 converts to 11111111 in binary: eight 1s, the largest unsigned value one byte can hold.

    You enter
    Number to convert255
    From baseDecimal (base 10)
    To baseBinary (base 2)
    The calculator returns
    Converted number11111111
    Decimal value255
    Binary (base 2)11111111
    Octal (base 8)377
    Hexadecimal (base 16)FF
    WorkingDecimal 255 to base 2: 255 ÷ 2 = 127 remainder 1 127 ÷ 2 = 63 remainder 1 63 ÷ 2 = 31 remainder 1 31 ÷ 2 = 15 remainder 1 15 ÷ 2 = 7 remainder 1 7 ÷ 2 = 3 remainder 1 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 Reading the remainders from last to first gives 11111111

    How to use this calculator

    1. Type the value in Number to convert, using letters for digits above 9, such as FF in hex.
    2. Choose its base in From base, then choose To base or All common bases.
    3. For another base, choose Custom base and enter it in Custom from base or Custom to base (2 to 36).
    4. Read Converted number. Decimal value, Binary, Octal and Hexadecimal show the value in the common bases, and Working lists the place-value and division steps line by line.

    Frequently asked questions

    How do you convert decimal to binary?

    Divide by 2, note the remainder, and repeat with the quotient until you reach 0. For 13: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Reading the remainders from the bottom up gives 1101.

    How do you convert binary to decimal?

    Write the place values 1, 2, 4, 8, 16 and so on from the right, then add those where the digit is 1. Binary 1010 has 1s in the 8 and 2 places, so it is 8 + 2 = 10.

    How do you convert hex to decimal?

    Multiply each digit by a power of 16, with A = 10 up to F = 15. FF is 15 × 16 + 15 = 255, and 1E is 1 × 16 + 14 = 30. Type the letters in capitals or lower case.

    Why do programmers use hexadecimal?

    One hex digit represents four binary digits, so a byte can be written as two hex digits, from 00 to FF. This makes long binary values easier to read and type, which is why memory addresses and web colours such as #FF8800 use hex.

    What is octal used for?

    A common use is Unix and Linux file permissions. Each octal digit covers three bits, one each for read, write and execute. So 755 means 111 101 101: read, write and execute for the owner, and read and execute for the group and others.

    What is the largest number this converter handles?

    9,007,199,254,740,991, which is 2^53 - 1 and 53 ones in binary. This is the largest safe integer for standard JavaScript numbers, so the calculator refuses larger values. It accepts only whole numbers of 0 or more, not negatives or fractions.

    Learn more

    Place value in any base

    In decimal, 345 means 3 × 100 + 4 × 10 + 5. Every base uses its own powers in the same way: binary places are 1, 2, 4, 8, 16 and so on, and hex places are 1, 16, 256, 4,096.

    Digits above 9

    A base needs as many digit symbols as its value. Above base 10, letters supply the extra symbols: hex uses 0 to 9 then A to F (10 to 15), and base 36 runs up to Z = 35.

    Grouping binary digits

    Because 16 = 2^4 and 8 = 2^3, you can convert binary to hex by grouping digits in fours from the right, or to octal by grouping them in threes. 11111111 is 1111 1111, or FF in hex, and 11 111 111, or 377 in octal.

    • Checking binary and hex answers in GCSE or A level computer science
    • Turning a colour value into hex: 255 is FF and 128 is 80
    • Reading Unix file permissions such as 755 as binary (111 101 101)
    • Working out subnet masks, where 255 is 11111111
    • Practising place value in bases such as 3 or 5

    Reading the remainders in the wrong order

    The last remainder is the leftmost digit. Writing them top to bottom gives the number backwards.

    Mixing up which base a number is in

    10 is two in binary, eight in octal and sixteen in hex. Write the base as a subscript (10₂) when it is not obvious.

    Using a digit the base does not have

    Binary has only 0 and 1, and octal stops at 7. The calculator reports an invalid digit if you enter one that does not belong to the chosen base.

    Forgetting the letter values in hex

    B is 11, not 2, so hex B0 is 11 × 16 = 176.

    • Learn the first eight powers of 2 (1, 2, 4, 8, 16, 32, 64, 128): these are the place values of one byte.
    • Split long binary numbers into groups of four from the right before reading off hex.
    • Leading zeros do not change a value: 00101 and 101 are both 5.

    Methodology and sources

    The calculator first converts the input to decimal by multiplying each digit by the base raised to its position. It then converts that value to the target base by dividing repeatedly and collecting the remainders, and the Working row shows both stages. Only whole numbers of 0 or more are supported, so a minus sign or decimal point gets a message rather than a result. Letters represent digits above 9 and can be typed in either case; results show them in capitals. Spaces and underscores between digit groups are ignored. Values above 9,007,199,254,740,991 (2^53 - 1) are refused because standard JavaScript numbers cannot represent every whole number above that limit exactly.