Suppose you want to print 768345 in base 10, one digit at a time. STAGE 1: Print them right-to-left (not sufficient for HW02) Calc remainder: 768345 % 10 = 5 This is the 1's place digit, aka the 10⁰ place. Calc quotient: 768345 / 10 = 76834 Calc remainder: 76834 % 10 = 4 This is the 10's place digit, aka the 10¹ place. 768345 / 10 % 10 = 4 ... because 76834 = 768345 / 10 Calc quotient: 76834 / 10 = 7683 Calc remainder: 7683 % 10 = 3 This is the 100's place digit, aka the 10² place. 768345 / 10² % 10 … because 7683 = 768345 / 10 / 10 = 768345 / 10². Calc quotient: 7683 / 10 = 768 Calc remainder: 768 % 10 = 8 This is the 1000's place digit, aka the 10³ place. 768345 / 10³ % 10 … because 768 = 768345 / 10 / 10 / 10 = 768345 / 10³ Calc quotient: 768 / 10 = 76 Calc remainder: 76 % 10 = 6 This is the 10,000s place digit, aka the 10⁴ place. 768345 / 10⁴ % 10 … because 76 = 768345 / 10 / 10 / 10 / 10 = 768345 / 10⁴ Calc quotient: 76 / 10 = 7 Calc remainder: 7 % 10 = 7 This is the 100,000s place digit, aka the 10⁵ place. 768345 / 10⁵ % 10 … because 7 = 768345 / 10 / 10 / 10 / 10 / 10 = 768345 / 10⁵ 7 / 10 = 0 We stop when the quotient is zero. ____________________________________________________________________________________________________ HERE IS A POSSIBLE THOUGHT PROCESS Question 1: If you knew how many digits a number will require to represent, could you tell me the first digit? Ex: If I give you 768336 and tell you that in base 10, it will require 6 digits, can you tell me that the first digit is '7'? First digit is 768336 ÷ 10⁵ Question 2: If you knew how many digits a number will require to represent, could you tell me the second digit? Ex: If I give you 768345 and tell you that in base 10, it will require 6 digits, can you tell me that the second digit is '6'? 768345 / 10⁴ % 10 Question 3: If you knew how many digits a number will require to represent, could you tell me the third digit? Ex: If I give you 768345 and tell you that in base 10, it will require 6 digits, can you tell me that the second digit is '8'? 768345 / 10³ % 10 Question 4: If you knew how many digits a number will require to represent, could you tell me the i'th digit? len_digits is the number of digits needed to represent the number. digit_num is the digit (starting at 1); for the left-most digit, digit_num==1, for the next digit, digit_num==2, and so on. 768345 / 10^(len_digits - digit_num) % 10 Question 5: If I give you a number and a radix (base), can you calculate the number of digits needed to represent the number in that base? You don't have to answer in terms of a closed-form math expression (though you could if you wanted to). Ex: If n==768345 and radix==10, can you tell me that it requires 6 digits to express? ____________________________________________________________________________________________________ Once you know the digit value for a particular place, how do you print the character? Example: If you wanted to print the number one-hundred sixty-three in base 16. Result: a3 16's place◀─┘└─▶1's place Digit value for the 16's place is ten. If digit_value is 0, we want to print '0'. If digit_value is 1, we want to print '1'. Remember: '1' is '0' + 1 If digit_value is 2, we want to print '2'. Remember: '2' is '0' + 2 If digit_value is 3, we want to print '3'. If digit_value is 4, we want to print '4'. If digit_value is 5, we want to print '5'. If digit_value is 6, we want to print '6'. If digit_value is 7, we want to print '7'. If digit_value is 8, we want to print '8'. If digit_value is 9, we want to print '9'. If digit_value is 10, we want to print 'a'. Remember: 'a' is 'a' + 0 If digit_value is 11, we want to print 'b'. Remember: 'b' is 'a' + 1 If digit_value is 12, we want to print 'c'. Remember: 'c' is 'a' + 2 If digit_value is 13, we want to print 'd'. If digit_value is 14, we want to print 'e'. If digit_value is 15, we want to print 'f'. If digit_value is 16, we want to print 'g'. If digit_value is 17, we want to print 'h'. If digit_value is 18, we want to print 'i'. If digit_value is 19, we want to print 'j'. If digit_value is 20, we want to print 'k'. If digit_value is 21, we want to print 'l'. If digit_value is 22, we want to print 'm'. If digit_value is 23, we want to print 'n'. If digit_value is 24, we want to print 'o'. If digit_value is 25, we want to print 'p'. If digit_value is 26, we want to print 'q'. If digit_value is 27, we want to print 'r'. If digit_value is 28, we want to print 's'. If digit_value is 29, we want to print 't'. If digit_value is 30, we want to print 'u'. If digit_value is 31, we want to print 'v'. If digit_value is 32, we want to print 'w'. If digit_value is 33, we want to print 'x'. If digit_value is 34, we want to print 'y'. If digit_value is 35, we want to print 'z'.