Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The requirements for making the c file and header file are as follows. I need an

ID: 3664712 • Letter: T

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 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 • exchange odd numbered bytes (1 with 3) • exchange even numbered bytes (0 with 2) • take the one’s complement of the number
Note for all operations, the final result is to be displayed in the designated base (see next item).

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. Exchange byte macros: Write and use two macros that perform the exchange operations:
. XODD(N): exchanges the odd numbered bytes with each other while leaving the content of the other bytes intact. It must be possible to use the macro as follows: n = XODD(n).

. XEVEN(N): exchanges the even numbered bytes with each other while leaving the content of the other bytes intact. It must be possible to use the macro as follows: n = XEVEN(n).
Note that these macro definitions must not call a subroutine; that is, the code must be “inline”. Also, the right most byte is to be considered byte 0 with the other bytes numbered sequentially from right to left.
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.

A sample of what the output should look like is as follows:
Sample output:
Input number: 857870592
Select option:
1 - display number in hexadecimal
2 - exchange odd bytes
3 - exchange even bytes
4 - take complement of number
5 - exit
1
number: 0x33221100
Select option:
1 - display number in hexadecimal
2 - exchange odd bytes
3 - exchange even bytes
4 - take complement of number
5 - exit
2
number before: 0x33221100
number after:   0x11223300
Select option:
1 - display number in binary
2 - exchange odd bytes
3 - exchange even bytes
4 - take complement of number
5 - exit

3
number before: 00110011001000100001000100000000
number after:   00110011000000000001000100100010
Select option:
1 - display number in binary
2 - exchange odd bytes
3 - exchange even bytes
4 - take complement of number
5 - exit

4
number before: 00110011000000000001000100100010
number after:   11001100111111111110111011011101

Explanation / Answer

Similar code sections for (b1)(b2)(b3); for example

printf(" Orig   is #%s# ", orig);

encb1( orig, secret, amt);

printf(" Secret is #%s# ", secret);

decb1( secret, show, amt );

printf(" Show   is #%s# ", show);

printf(" Orig   is #%s# ", orig);

encb2( orig, secret);

printf(" Secret is #%s# ", secret);

decb2( secret, show);

printf(" Show   is #%s# ", show);