Question
The requirements for making the c file and header file are as follows. I need an example of a program that makes use of bit-wise
The requirements for making the c file and header file are as follows. I need an example of a program that makes use of bit-wise operators in the way described below.
Requirements:
1. Whenever possible you must make use of bit-wise operators (not arithmetic operators).
2. header file: In addition to a .c file, also write and use a header (.h) file. Include in this header file your #define statements and other appropriate items.
3. main routine: The main routine is to loop displaying a menu of options and then to perform the selected operation on an input integer number. The operations to be displayed / performed are the following:
display number in designated base
shift number left circular by one digit in the designated base
shift number right circular by one digit in the designated base
set the nth digit of the number to zero Note for all operations, the final result is to be displayed in the designated base.
4. display routine: Write one function that takes an integer value as an input argument and then displays the number in the designated base. The base is either binary, decimal or hexadecimal. The selection of base is to be made at compile time via the D option. Instead of having three separate routines, one for binary, one for decimal and one for hexadecimal, you are to write one routine some of whose statements vary based on the selection of base. This variation of statements is to be controlled via conditional pre-processor directives.
5. Shift left / rightmacros: Write two macros. SRC is to take the argument and shift it right circular by one digit in the designated base. The other, SLC, is to take the argument and shift it left circular by one digit in the designate base. So, for example, if value is 0x0A0B0C0D initially, then it must be possible to use the SLC macro as follows: value = SLC(value); and value should then contain 0xA0B0C0D0. The macros are to be inline code; that is, they are not to call any function to produce the result. Your program must use these macros to process the shift menu options.
6. Readability: Your program must be written using good C programming conventions:
Variable names and function names should be descriptive of what they represent.
Use indentation to show the structure of the program. Typically this means using indentation with for, while, do-while, if, and switch statements as well as indenting the body of functions. Indentation should show the nesting level of the statements involved.
Include some in-line documentation to give a high level view of what the program and groups of statements is/are doing.
Sample output:
Input number: 2271560481
Select option:
1 -display number in hexadecimal
2 -shift left circular one digit
3 -shift right circular one digit
4 set digit n to zero
5 -exit 1
0x87654321
Select option:
1 -display number in hexadecimal
2 -shift left circular one digit
3 -shift right circular one digit
4 -set digit n to zero 5 -exit
2
0x76543218
Select option:
1 -display number in hexadecimal
2 -shift left circular one digit
3 -shift right circular one digit
4 -set digit n to zero 5 exit
3
0x87654321
Select option:
1 -display number in hexadecimal
2 -shift left circular one digit
3 -shift right circular one digit
4-set digit n to zero 5 -exit
3
0x18765432
Input number: 2153791520
Select option:
1 -display number in binary
2 -shift left circular one digit
3 -shift right circular one digit
4 -set digit n to zero
5 - exit 1
10000000011000000100000000100000
Select option:
1 -display number in binary
2 -shift left circular one digit
3 -shift right circular one digit
4 -set digit n to zero 5 -exit
3
01000000001100000010000000010000
Select option:
1 -display number in binary
2 -shift left circular one digit
3 -shift right circular one digit
4 -set digit n to zero
5 -exit 4 specify digit to be zeroed: 30
00000000001100000010000000010000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started