Have to use C language Pseudocode A #define called BITS should be set at the top of...

70.2K

Verified Solution

Question

Programming

Have to use C language
Pseudocode
A #define called BITS should be set at the top of the program. Itshould be set to 8 when the program is submitted. This
define should be used throughout the entire program whensetting/using array sizes/max element. This define will also
be used in the output to print 8-bit vs 16 bit. Your program shouldfunction whether the define is set to 8 or to 16.
Part of the grading process will be to change the define from 8 to16 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 onescanf() to store all three values.
While either number is less than 0 or more than 255, continue toprompt for input until a valid number is entered (hint
– use a while loop). See sample output below.
Call function ConvertDecimalToBinary() to convert the first numberto binary.
Call function ConvertDecimalToBinary() to convert the second numberto binary.
If the entered operator is an allowed operator, then convert theresult to binary and print the decimal result and
binary result as seen in the sample code.
ConvertDecimalToBinary()
Return type : void
Parameters :
int containing the decimal value to be converted
char array (hint : the array is passed empty from main() and thisfunction fills it so when the function
finishes, the array back in main() will contain the values added inthe function).
This function will use a method of decimal to binary conversioncalled “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 eachdivide by 2 which will be accomplished using
bitshifting instead of division to divide the number in half. Use abitmask to determine if an array element if odd (1) or
even (0). YOU MUST USE THIS METHOD IN THIS ASSIGNMENT.
Using a for loop, loop over the int array and write each elementinto the char array that was passed in. Hint : keep
in mind what the ASCII value is for the number zero when writingthe int array element into the char array. If you
store the number 65 in a char, it will be ‘A’ so if you want tostore the number 0 in a char array, you will need to …?
HINT : make sure your char arrays are one bigger than the number ofBITS 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 decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 2 & 3
In base 10...
2 & 3 = 2
In 8-bit base 2...
00000010
&
00000011
========
00000010
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
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 decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
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
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 2 << 3
In base 10...
2 << 3 = 16
In 8-bit base 2...
00000010 << 3
00010000
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 2 >> 3
In base 10...
2 >> 3 = 0
In 8-bit base 2...
00000010 >> 3
00000000
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 100 >> 3
In base 10...
100 >> 3 = 12
In 8-bit base 2...
01100100 >> 3
00001100
--------------------------------------------------------------------------------------
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 2 * 3
Operator * is not supported by this calculator
Change
#define BITS 8
to
#define BITS 16
Bitwise Calculator
Enter two base 10 values with a bitwise operator to see the decimalresult
and the binary result. The format is
FirstNumber BitwiseOperator SecondNumber
For example, enter the expression
2 & 3
This calculator can used with &, |, ^, << and>>
Please note that the spaces between numbers and operator isessential
and the two entered values must be between 0 and 255
Enter expression 4 & 6
In base 10...
4 & 6 = 4
In 16-bit base 2...
0000000000000100
&
0000000000000110
========
0000000000000100

If you have questions please ask .. Thank you.

Answer & Explanation Solved by verified expert
3.8 Ratings (706 Votes)
include define BITS    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students