Exam-like Problems - Base Conversions¶
Your worked out solutions are due Fri Sep 19th at 11:59pm
You must submit problems.pdf in your lab04 GitHub Repo
You will have time to work on these problems in Lab section this week
Put the solutions to the following problem in a file called problems.pdf in your Lab02 GitHub Repo. You can typeset your solutions or you can write your solutions by hand and scan or take a photo of your work. Just be sure to put your solution in a single file called problems.pdf. If you don't use this EXACT name in all lowercase you won't get credit.
I recommend that you handwrite your solutions because this will give you practice with handwriting on the exam.
Note I will not grade you on correctness in your answers; I'm just looking to see that you attemped the problems and that you show your work.
Question 1 - Hex to Decimal¶
Convert the hexadecimal number 0x3FA to decimal. Show your work.
Question 2 - Binary to Decimal¶
Convert the binary number 0b10110 to decimal. Show your work.
Question 3 - Decimal to Binary¶
Convert the decimal number 231 to binary. Show your work.
Question 4 - Bad string_to_int()¶
Consider the following incorrect implementation of string_to_int():
int string_to_int(char *s) {
int result = 0;
for (int i = 0; s[i] != '\0'; i++) {
result = result * 10 + s[i];
}
return result;
}
This function is supposed to convert a string of digits into an integer. However, it does not work as expected. Identify and explain the problem with this code. Show the corrected version.