Question: Question 2 : Write a program which will prompt for and read a string that represents an eight digit base - 4 number ( i
Question : Write a program which will prompt for and read a string that represents an eight digit base number i e only the digits may appear in the number The program will then echo the users input and print the base number as a four digit hexadecimal number. The program will keep prompting for base numbers until the user enters a blank line i e the user hits only the enter key at which time it will terminate.
To do this you will need to convert the string of characters representing the base number into a binary number or any other way. The conversion will be done as follows: create an array of eight byteword in the memory call POWERFOUR which contains powers of corresponding to the digits in the base number Now process each of the characters in the string by first converting its ascii code into the integer value it represents, then multiplying it by the corresponding element in POWERFOUR, and then adding this product into the binary number. Once all the characters have been processed, the number can be printed as digit hexadecimal number.
Here is a high level description of the programs operation:
prompt the user for a number
read the users input intoa buffer in memory
Check the length of the input. If the length is then the user has entered a blank line and you should end the program. If the length is greater than the user entered a number which is processed.
Convert the string into a binary number using the method above or other method
Print the binary number as a hexadecimal number
Return to step
You may assume there are no errors in the input, i e the user will always enter either an digit base number or a blank line.
The output for your program should look approximately like this:
Student Number :
Course: COSC
Instructor: Simon Xu
Assignment:
Question:
Enter an digit base number
Or enter a blank line to quit:
base CC base
Enter an digit base number
Or enter a blank line to quit:
base EEbase
Enter an digit base number
Or enter a blank line to quit:
Program ended normally
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
