# Base b arithmetic

From CS2800 wiki

You are already familiar with several digit-by-digit algorithms for working with decimal numbers, such as long addition, long multiplication, and long division.

It turns out that these algorithms also work in base b; one just needs to represent digits in base . For example, to add and , we can add them digit by digit, starting from the right, and handling carries appropriately. We would add 6 and 4 to get the number 10, which is represented by ; we would keep the 3 and carry the 1. We would then add the carry and the second digits to get ; again we keep the 2 and carry the 1. Finally we add the third digit and the carry to get the third digit 2; this gives us .

1 | 2 | 4 | ||

+ | 6 | 6 | (base 7) | |

2 | 2 | 3 |

You could prove that these algorithms all work using induction.