- Decimal is base 10.
- There are 10 digits in counting (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
- When you reach 10, you carry a “1” over to the next column
- The number after 9 is 10
- Hexadecimal is base 16.
- There are 16 digits in counting (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F)
- When you reach 16, you carry a “1” over to the next column
- The number after F (decimal 15) is 10 in hex (or 16 in decimal)
Addition
Use the following steps to perform hexadecimal addition:1. Add one column at a time.
2. Convert to decimal and add the numbers.
3a. If the result of step two is 16 or larger subtract the result from 16 and carry 1 to the next column.
3b. If the result of step two is less than 16, convert the number to hexadecimal.
Example:
AC5A916 + ED69416
Step 1:
2. Convert to decimal & add (9 + 4 = 13)
3. Follow less than 16 rule
Decimal 13 is hexadecimal DStep 2:
2. Convert
to decimal & add (10 + 9 = 19)
3. Follow
16 or larger than 16 rule
(19 – 16 = 3 carry a 1)
Step 3:
2. Convert
to decimal & add (1 + 5 + 6 = 12)
3. Follow
less than 16 rule, convert to hex
Decimal 12 is hexadecimal C
Step 4:
2. Convert
to decimal & add (12 + 13 = 25)
3. Follow
16 or larger than 16 rule
(25 – 16 = 9 carry a 1)
Step 5:
2. Convert
and add (1
+ 10
+ 11
= 22)
3. Follow
16 or larger than 16 rule
(22 – 16 = 6 carry a 1)
Step 6:
2. Convert
and add (1
+ 0 + 0 = 1)
3. Follow less than 16 rule
Subtraction
It works pretty much the same with addition, the main difference is to borrow value from left digit for subtracting higher value numbers.Example 1:
C67516 - A24716
When a borrow is required from the digit to the left, add 16 (decimal) to the current digit's value.
Example 2:
1C56F016 - FABD216
1C56F0- FABD2CAB1E
Method:
- 0 - 2, can't do so borrow 16 from next column, 16 - 2 =14 i.e. E
- F (borrowed 1) so now E - D which is 14 - 13 = 1
- 6 - B, can't do, so borrow 16 from next column, 22 (16+ 6) - 11 = 11, i.e. B
- 5 (borrowed 1) so now 4 - A, can't do so borrow, 16 from next column, 20 (16+ 4) - 10 = 10 i.e. A
- C (borrowed 1) so now B - F, can't do so borrow, 16 from next column, 27 (16+ 11) - 15 = 12 i.e. C
No comments:
Post a Comment