Question: write a plain C program named convert.c, there is a function called digit_btoi which takes two arguments, a character and a number. The character is
write a plain C program named convert.c, there is a function called digit_btoi which takes two arguments, a character and a number.
The character is the string representation of a digit in the following base.
The number is that representations base.
digit_btoi has a return value of integer and should return the value of the digit as a number.
Remember, after representations of base 11 and higher, we need to use more than just the usual ASCII numbers for digits. For example, in Base 16, we need to use all the way to F to represent 15.
This function should work on the following characters up to the last digit used in the base:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
For example, in base 16, only the following digits should be acceptable
0123456789ABCDEF
For any digit invalid digit or invalid base, the function should return -1 or INVALID_DIGIT.
But for base 36, all numbers and letters should be used. Also, make sure that the function works with lowercase or uppercase digits.
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789abcdefghijklmnopqrstuvwxyz
Example values:
digit_btoi('0', 16) = 0
digit_btoi('F', 16) = 15
digit_btoi('1', 16) = 1
digit_btoi('Z', 36) = 35
digit_btoi('z', 36) = 35
digit_btoi('q', 10) = -1
digit_btoi('@', 10) = -1
digit_btoi('9', 0) = -1
Youre only expected to implement from base 2 to up base 36 in this assignment. All other bases should be considered invalid. (Technically, you can do base 1, but it would be the number system consisting only of 0's).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
