Understanding hexadecimal numbers
Hexadecimal looks strange the first time you meet it, and then it becomes the most natural way to write numbers in computing. It is base 16, so it counts 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, and then 10 — where 10 in hex means sixteen, not ten. The reason computers use it is simple: one hex digit holds exactly four bits, so a byte is two hex digits, and a colour like #FF5733 is three bytes written as six hex digits.
Formula and method
The digits A–F have the values 10–15: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
Method: convert each input to an integer, perform the operation, then return to the selected base. The operation is performed on the decimal integers, and the result is converted back to hex. How the conversion works. Read a hex number from right to left, multiplying each digit by 16 raised to its position: the rightmost digit by 16⁰ = 1, the next by 16¹ = 16, the next by 16² = 256, and so on. So 109 in hex is 1 × 256 + 0 × 16 + 9 × 1 = 265, and 1A is 1 × 16 + 10 = 26. To convert back, divide the decimal result by 16 repeatedly and read the remainders from last to first: 265 ÷ 16 = 16 remainder 9, 16 ÷ 16 = 1 remainder 0, 1 ÷ 16 = 0 remainder 1, giving the digits 1, 0, 9. The operation you select is applied to the two converted integers, and the result is shown in hex; a negative result from a subtraction is shown with a minus sign, and a division result is the whole-number quotient in hex.
Worked example
Example 1 — FF + A (the live-page example) The first hex integer is FF, the second is A, and the operation is addition. Convert: FF = 15 × 16 + 15 = 240 + 15 = 255; A = 10 Add: 255 + 10 = 265 Convert back: 265 ÷ 16 = 16 remainder 9; 16 ÷ 16 = 1 remainder 0; 1 ÷ 16 = 0 remainder 1 → digits 1, 0, 9 = 109 The result is 109 in hex. The answer looks smaller than either input, which is the classic surprise of hex arithmetic: 109 in hex is 265 in decimal, larger than both 255 and 10, but written with fewer digits because each hex digit carries more value.