CalcTrace

Binary Calculator

Convert a number between binary, decimal, octal and hexadecimal, add, subtract, multiply or divide binary numbers, apply bitwise AND, OR, XOR, NOT and shifts, or find the two’s complement form of a negative number at 4, 8, 16, 32 or 64 bits. Every answer is shown in all four bases with the steps behind it.

Last updated .

What do you want to do?

Mode

Result

182 (decimal) in binary

–

–Binary
–Decimal
–Octal
–Hexadecimal

Show the working

    How binary numbers work

    Binary is a place-value system like decimal, but each place is worth twice the one to its right instead of ten times. The only digits are 0 and 1, called bits.

    Value = dn × 2n + … + d2 × 4 + d1 × 2 + d0 × 1

    Each d is one bit, and its subscript is its position counted from 0 at the right-hand end. So 1011 0110 is 128 + 32 + 16 + 4 + 2 = 182. Octal (base 8) and hexadecimal (base 16) follow the same rule with powers of 8 and 16, and exist mainly as shorthand for binary: one octal digit stands for exactly three bits and one hex digit for exactly four. Splitting 1011 0110 into fours gives B and 6, so it is B6 in hex. Splitting it into threes from the right gives 10, 110, 110, which is 266 in octal.

    Decimal to binary: divide by 2 repeatedly and read the remainders from last to first

    Worked examples

    Converting 156 to binary

    1. 156 ÷ 2 = 78 remainder 0
    2. 78 ÷ 2 = 39 remainder 0
    3. 39 ÷ 2 = 19 remainder 1
    4. 19 ÷ 2 = 9 remainder 1
    5. 9 ÷ 2 = 4 remainder 1
    6. 4 ÷ 2 = 2 remainder 0
    7. 2 ÷ 2 = 1 remainder 0
    8. 1 ÷ 2 = 0 remainder 1

    Reading the remainders upwards gives 1001 1100. Check: 128 + 16 + 8 + 4 = 156. In hex that is 9C.

    Adding 1011 and 110

    Binary addition has four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). Working from the right: 1 + 0 = 1. Then 1 + 1 = 10, write 0 and carry 1. Then 0 + 1 + 1 = 10, write 0 and carry 1. Then 1 + 0 + 1 = 10, write 0 and carry 1. The final carry goes in front, giving 10001. In decimal that is 11 + 6 = 17. With the same two numbers, 1011 − 110 = 101 (5), 1011 × 110 = 1000010 (66), and 1011 ÷ 110 = 1 remainder 101.

    Bitwise operations

    Bitwise operations treat a number as a row of separate switches and compare two numbers column by column, with no carrying.

    OperationRule for each column1100 with 1010
    AND1 only if both bits are 11000
    OR1 if either bit is 11110
    XOR1 if the bits differ0110

    NOT flips every bit, so it only has a definite answer once the width is fixed: at 8 bits, NOT 0000 1111 is 1111 0000. A left shift moves every bit towards the high end and fills with zeros, which doubles the number for each place. 10110 (22) shifted left by 2 is 1011000 (88). A right shift drops bits off the low end, halving and rounding down: 22 shifted right by 2 is 101 (5).

    The commonest practical use is masking. AND with a pattern of 1s keeps just those bits: 182 AND 15 keeps the lowest four bits of 1011 0110 and returns 0110, which is 6. Network subnet masks, file permissions and hardware flags all work this way.

    Two’s complement

    Computers store negative whole numbers in two’s complement, because it lets the same adding circuit handle both signs.

    Pattern for −x at w bits = 2w − x, which is the same as inverting the bits of x and adding 1

    Here x is the size of the number without its sign and w is the bit width. To store −42 in 8 bits: 42 is 0010 1010. Inverting gives 1101 0101, and adding 1 gives 1101 0110. As an unsigned number that pattern is 214, and 256 − 42 = 214. The leftmost bit acts as the sign: 1 means negative.

    The width sets the range. With w bits the values run from −2w−1 to 2w−1 − 1:

    There is one more negative value than positive, because zero takes one of the non-negative patterns.

    Common mistakes

    This page works with whole numbers of up to 64 bits. Binary fractions and floating-point formats are outside its scope.