Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coding Assignment 2 1. The format and content of the output is not a suggestion it is the specification given to you to follow so

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Coding Assignment 2 1. The format and content of the output is not a suggestion it is the specification given to you to follow so please follow it exactly. Points will be lost for not following the specification. Formatting the output to look exactly the same is part of exercises in this assignment. 2. Please note that part of the rubric is how you coded the program in addition to outputting valid responses. Be sure to review the rubric before submitting your code. 3. Make sure your name and student id are in a comment in the first line of your program. 4. Name your program Code2_studentid.cand name the zip file Code2_studentid.zip for submission to Canvas. Pseudocode A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This define should be used throughout the entire program when setting/using array sizes/max element. This define will also be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16. Part of the grading process will be to change the define from 8 to 16 and to recompile your program to see if your program still runs properly. See sample output. main() Print instructions (see sample output below) Prompt for and store both numbers and the operator. Use only one scanf() to store all three values. While either number is less than 0 or more than 255, continue to prompt for input until a valid number is entered (hint - use a while loop). See sample output below. Call function ConvertDecimalToBinary () to convert the first number to binary. Call function Convert DecimalToBinary () to convert the second number to binary. If the entered operator is an allowed operator, then use the decimal versions of the values with the operator and convert the result to binary and print the decimal result and binary result as seen in the sample code. Convert DecimalToBinary ( ) Return type : void Parameters: int containing the decimal value to be converted char array (hint: the array is passed empty from main () and this function fills it so when the function finishes, the array back in main () will contain the values added in the function). This function will use a method of decimal to binary conversion called Divide in Half, Ignore the Remainder. Please watch the following video for a demonstration of the method. https://youtu.be/xdZqk8BXPwg Create a local int array. This array will store the result of each divide by 2 which will be accomplished using bitshifting instead of division to divide the number in half. Use a bitmask to determine if an array element if odd (1) or even (O). YOU MUST USE THIS METHOD IN THIS ASSIGNMENT. Using a for loop, loop over the int array and write each element into the char array that was passed in. Hint : keep in mind what the ASCII value is for the number zero when writing the int array element into the char array. If you store the number 65 in a char, it will be Aso if you want to store the number O in a char array, you will need to ...? HINT : make sure your char arrays are one bigger than the number of BITS so that you have room for the null terminator so that %s prints correctly. Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 1 2 & 3 This calculator can used with &, 1, ^, > Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2 & 3 In base 10... 12 & 3 = 2 In 8-bit base 2... 00000010 & 00000011 ======== 00000010 Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 2 & 3 This calculator can used with &, T, ^, and >> Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2 | 3 In base 10... 2 3 = 3 In 8-bit base 2... 00000010 00000011 00000011 Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 2 & 3 This calculator can used with &, , ^, > Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2^ 3 In base 10... 2 ^ 3 = 1 In 8-bit base 2... 00000010 00000011 00000001 Coding Assignment 2 1. The format and content of the output is not a suggestion it is the specification given to you to follow so please follow it exactly. Points will be lost for not following the specification. Formatting the output to look exactly the same is part of exercises in this assignment. 2. Please note that part of the rubric is how you coded the program in addition to outputting valid responses. Be sure to review the rubric before submitting your code. 3. Make sure your name and student id are in a comment in the first line of your program. 4. Name your program Code2_studentid.cand name the zip file Code2_studentid.zip for submission to Canvas. Pseudocode A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This define should be used throughout the entire program when setting/using array sizes/max element. This define will also be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16. Part of the grading process will be to change the define from 8 to 16 and to recompile your program to see if your program still runs properly. See sample output. main() Print instructions (see sample output below) Prompt for and store both numbers and the operator. Use only one scanf() to store all three values. While either number is less than 0 or more than 255, continue to prompt for input until a valid number is entered (hint - use a while loop). See sample output below. Call function ConvertDecimalToBinary () to convert the first number to binary. Call function Convert DecimalToBinary () to convert the second number to binary. If the entered operator is an allowed operator, then use the decimal versions of the values with the operator and convert the result to binary and print the decimal result and binary result as seen in the sample code. Convert DecimalToBinary ( ) Return type : void Parameters: int containing the decimal value to be converted char array (hint: the array is passed empty from main () and this function fills it so when the function finishes, the array back in main () will contain the values added in the function). This function will use a method of decimal to binary conversion called Divide in Half, Ignore the Remainder. Please watch the following video for a demonstration of the method. https://youtu.be/xdZqk8BXPwg Create a local int array. This array will store the result of each divide by 2 which will be accomplished using bitshifting instead of division to divide the number in half. Use a bitmask to determine if an array element if odd (1) or even (O). YOU MUST USE THIS METHOD IN THIS ASSIGNMENT. Using a for loop, loop over the int array and write each element into the char array that was passed in. Hint : keep in mind what the ASCII value is for the number zero when writing the int array element into the char array. If you store the number 65 in a char, it will be Aso if you want to store the number O in a char array, you will need to ...? HINT : make sure your char arrays are one bigger than the number of BITS so that you have room for the null terminator so that %s prints correctly. Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 1 2 & 3 This calculator can used with &, 1, ^, > Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2 & 3 In base 10... 12 & 3 = 2 In 8-bit base 2... 00000010 & 00000011 ======== 00000010 Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 2 & 3 This calculator can used with &, T, ^, and >> Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2 | 3 In base 10... 2 3 = 3 In 8-bit base 2... 00000010 00000011 00000011 Bitwise Calculator Enter two base 10 values with a bitwise operator to see the decimal result and the binary result. The format is FirstNumber BitwiseOperator SecondNumber For example, enter the expression 2 & 3 This calculator can used with &, , ^, > Please note that the spaces between numbers and operator is essential and the two entered values must be between 0 and 255 Enter expression 2^ 3 In base 10... 2 ^ 3 = 1 In 8-bit base 2... 00000010 00000011 00000001

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago