CalcTrace

Hex Calculator

Add, subtract, multiply or divide hexadecimal numbers, convert between hexadecimal, decimal and binary, or turn a hex colour code such as #0B6B5D into its red, green and blue values and back. Each answer comes with the working, and colours are shown as a swatch.

Last updated .

What do you want to do?

Mode
Operation

Result

2F + 3C =

–

–Hexadecimal
–Decimal
–Binary
–Octal

Show the working

    How hexadecimal works

    Hexadecimal, or hex, is base 16. It needs sixteen digits, so after 0 to 9 it borrows the letters A to F for the values 10 to 15. Each place is worth sixteen times the one to its right.

    Value = dn × 16n + … + d2 × 256 + d1 × 16 + d0 × 1

    Each d is one hex digit and its subscript is its position, counted from 0 at the right. So 2F is 2 × 16 + 15 = 47, and 1A3 is 1 × 256 + 10 × 16 + 3 = 419. Hex is popular in computing because 16 is 24: one hex digit stands for exactly four binary digits, so a byte of eight bits is always two hex digits. FF is 1111 1111, which is 255.

    Decimal to hex: divide by 16 repeatedly and read the remainders from last to first

    Worked examples

    Converting 48,879 to hex

    1. 48,879 ÷ 16 = 3,054 remainder 15, which is F
    2. 3,054 ÷ 16 = 190 remainder 14, which is E
    3. 190 ÷ 16 = 11 remainder 14, which is E
    4. 11 ÷ 16 = 0 remainder 11, which is B

    Reading the remainders upwards gives BEEF.

    Adding 2F and 3C

    1. Right-hand column. F + C is 15 + 12 = 27. That is one sixteen and 11 left over, so write B and carry 1.
    2. Next column. 2 + 3 + the carried 1 = 6. Write 6.

    The answer is 6B. In decimal the same sum is 47 + 60 = 107, and 6 × 16 + 11 = 107. The only difference from decimal addition is that you carry when a column reaches 16 instead of 10.

    The other operations follow the same pattern, or you can convert to decimal, calculate, and convert back, which is what the working on this page shows. 3C − 2F = D (13). FF × FF = FE01 (255 × 255 = 65,025). Hex 100 ÷ 7 = 24 remainder 4, because 256 = 36 × 7 + 4 and 36 is 24 in hex.

    Hex colour codes

    Screens mix colours from red, green and blue light, each set to a level from 0 to 255. A hex colour code writes those three levels as three two-digit hex numbers in a row, after a # sign.

    #RRGGBB: red = RR, green = GG, blue = BB, each from 00 (0) to FF (255)

    For #0B6B5D, the green used on this site: 0B is 0 × 16 + 11 = 11, 6B is 6 × 16 + 11 = 107, and 5D is 5 × 16 + 13 = 93, so the colour is rgb(11, 107, 93). Going the other way, divide each value by 16: 107 ÷ 16 = 6 remainder 11, giving 6B.

    Three levels of 256 steps each give 256 × 256 × 256 = 16,777,216 possible colours. A few variations are worth knowing:

    The calculator also reports the contrast ratio of white and of black text on the colour, using the formula in the Web Content Accessibility Guidelines. Body text should reach at least 4.5 to 1. White on #0B6B5D scores about 6.4 to 1, so it passes, while white on #FF8800 scores about 2.4 to 1 and does not.

    Common mistakes

    This page works with whole numbers. A negative result, such as 2F − 3C, is shown with a minus sign (−D). To see how a computer would store it, use the two’s complement mode of the binary calculator.