Addition
Adding hexadecimal numbers is very much the same as adding decimal numbers. In the context of web colors and RGB values, adding very one or two to an RGB color component might be useful on the odd occasion but unless your are interested in computer architecture, there aren't many situations where this kind of hexadecimal arithmetic is needed in the context of web colors.
When adding decimals, a number is carried over into the next column when the sum of two numbers is greater than 9. In hexadecimal addition, a number is carried over when the sum of two hexadecimal numbers is greater than 15.
For example:
$8 + $C = $14
This sum may look a little strange but if we look at the decimal equivalent, 8 + 12 = 20, it makes sense. Twenty is four more than sixteen so we put a 4 down in the ones column and carry a 1 over into the sixteens column.
A more complicated example:
$2D + $04 = $31
Breaking it down into columns, we are adding 4 to D, which is the equivalent of 4 + 13 = 17 = $11. Seventeen is one more than sixteen so 1 is marked in the ones column and a 1 is carried over into the sixteens column. The one that is carried over is added to the two that is already in the sixteens column giving 3.
Subtraction
Subtraction is no different:
$A3 - $0D = $96
Looking at the columns again, $D (13) is being subtracted from $3. There is not enough in the ones column so we must borrow one from the sixteens column. This reduces the sixteen column to $9 and leaves $13 in the ones column for $D to be subtracted from.
Navigate this article:
Intro
1 |
2 |
3 | 4