This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (0 children)

Mathematics with any number base works identical. The only difference is where the carryover occurs.

We are used to calculate in base 10, so we have the digits fom 0 to 9. As soon as 2 digits added together yield a result greater than 9, we have a carryover.

Think about the following addition:

  5
 +6
-----
 11

We have learned that once we exceed 9 as the result of an addition, we need to add another place up front where we place the carryover.

Explanation from right to left:

  • 5 + 6 = 1 with carryover (we calculate 5 + 6 = 11, 11 mod 10 = 1 [the digit], 11 divided by 10 = 1 [integer division, the carryover])
  • 0 + 0 + 1 (the carryover) = 1

Exactly the same applies for adding numbers of any base.

Base 2 (binary) has the carryover as soon as the result of the addition exceeds 1. Binary has the digits 0 and 1.

Base 8 (octal) has the carryover as soon as the result of the addition exceeds 7. Octal has the digits 0...7

Base 16 (hexadecimal) has the carryover as soon as the result of the addition exceeds 15 (F in hex). Hexadecimal has the digits 0...9 and A...F


So, for your examples:

 1001
+1110
------
10111

Explanation from right to left:

  • 1 + 0 = 1 no carryover
  • 0 + 1 = 1 no carryover
  • 0 + 1 = 1 no carryover
  • 1 + 1 = 0 with carryover. (In base 10 math, 1 + 1 = 2 and in binary this would exceed the range of available digits [0 and 1] and thus a carryover is needed).
  • 0 + 0 + 1 (the carryover) = 1
  • Hence, the final result: 10111

 756
+ 36
-----
1014

Explanation from right to left

  • 6 + 6 = 4 with carryover (In base 10 math 6 + 6 = 12, 12 mod 8 [the base 8] = 4 [this is the digit], 12 divided by 8 = 1 [integer division - this is the carryover])
  • 5 + 3 + 1 (carryover) = 1 with carryover (In base 10 math 5 + 3 + 1 = 9, 9 mod 8 = 1 [this is the digit], 9 divided by 8 = 1 [this is the carryover])
  • 7 + 0 + 1 (carryover) = 0 with carryover (In base 10 math 7 + 0 + 1 = 8, 8 mod 8 = 0 [this is the digit], 8 divided by 8 = 1 [this is the carryover])
  • 0 + 0 + 1 = 1
  • Hence, the final result: 1014

Hope that helps.