2.2 Going from Decimal to Other Numbering Systems
Now that you have a working knowledge of the Euclidean algorithm, I think now is a good time to apply this algorithm in the context of BS1009: Introduction to Computational Thinking.
2.2.1 Example #1
Suppose that I wanted to convert the decimal number 5110 to binary. Here’s what I would do using the Euclidean algorithm; I would first start by dividing 51 by 2. The remainder of that division will be the first, rightmost digit on my converted number:
51=2(25)+1
Hence, my first digit is going to be a 1. We then repeat the above process until the quotient is too small to be divided further. When this happens, the quotient is then the last digit (from the right) of our converted number:
25=2(12)+112=2(6)+06=2(3)+03=2(1)+1
Hence, we see that 5110=1100112 in binary. I can verify this using the material presented in the lecture:
1×20+1×21+0×22+0×23+1×24+1×25?=5132+16+2+1?=5151✓=51
And it works!
2.2.2 Example #2
Now, I want to convert the decimal number 41310 to hexadecimal. The process still remains the same using the Euclidean algorithm, but instead of dividing by 2, I will divide by 16 this time:
413=16(25)+1325=16(1)+9
Hence, 41310=19D16. Again, I can verify this:
D×160+9×161+1×162?=41313+144+256?=413413✓=413
And it also works!