Hex Calculator

Enter two hex numbers and choose an operation.

Operation

AND, OR and XOR compare the numbers digit by digit.

Digits 0–9 and A–F, with an optional 0x; a leading minus sign is allowed.

Digits 0–9 and A–F, with an optional 0x; a leading minus sign is allowed.

Try

Result

You entered116 − FF16\mathrm{1}_{16}\ -\ \mathrm{FF}_{16}

116 − FF16=−FE16\displaystyle \mathrm{1}_{16}\ -\ \mathrm{FF}_{16} = -\mathrm{FE}_{16}

Decimal

1−255=−254\displaystyle 1 - 255 = -254

Binary

−111111102\displaystyle -\mathrm{11111110}_{2}
Show the work
  1. Hex to decimal

    Each hex digit is worth a power of 1616, counting from 00 at the right, with A to F standing for 10 to 15. Converting both numbers to decimal lets the operation be done with ordinary arithmetic.

    Using N=dk 16k+⋯+d1 16+d0N = d_{k}\,16^{k} + \cdots + d_{1}\,16 + d_{0}

    116=1×160=1FF16=15×161+15×160=240+15=255\begin{gathered} \mathrm{1}_{16} = 1 \times 16^{0} = 1 \\ \mathrm{FF}_{16} = 15 \times 16^{1} + 15 \times 16^{0} = 240 + 15 = 255 \end{gathered}
  2. Subtraction in decimal

    The second number is larger, so the difference is negative: it is the difference of the sizes with a minus sign.

    1−255=−2541 - 255 = -254
  3. Decimal to hex

    Divide by 1616 again and again, keeping each remainder, until the quotient is 00. The remainders read from the last to the first are the hex digits, with 10 to 15 written as A to F, with the minus sign put back in front.

    Using N=16×q+r,0≤r<16N = 16 \times q + r, \quad 0 \le r < 16

    254=16×15+14(14→E)15=16×0+15(15→F)\begin{array}{l} 254 = 16 \times 15 + 14 \quad \left(14 \to \mathrm{E}\right) \\ 15 = 16 \times 0 + 15 \quad \left(15 \to \mathrm{F}\right) \end{array}
  4. Result

    So 116 − FF16=−FE16\mathrm{1}_{16}\ -\ \mathrm{FF}_{16} = -\mathrm{FE}_{16}.

Worked examples