Homework Solution: The requirements for making the c file and header file are as follows. I need an example of a pro…

    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

    Expert Answer

    The requirements coercion making the c smooth and header smooth are as follows. I want an sample of a program that moulds manifestation of bit-wise operators in the habit pictorial beneath.

    Requirements:

    1. Whenever practicable you must mould manifestation of bit-wise operators (not attributable attributable arithmetic operators).

    2. header smooth: In specification to a .c smooth, so transcribe and manifestation a header (.h) smooth. Include in this header smooth your #settle announcements and other misapply items.

    3. ocean system: The ocean system is to loop exhibiting a menu of non-interferences and then to effect the clarified action on an input integer estimate. The actions to be exhibited / effected are the following:

    • exhibit estimate in determined disesteemed

    • transfer estimate left spherical by individual digit in the determined disesteemed

    • transfer estimate direct spherical by individual digit in the determined disesteemed

    • coercionmal the nth digit of the estimate to naught Not attributable attributable attributable attributable attributablee coercion whole actions, the conclusive conclusion is to be exhibited in the determined disesteemed.

    4. exhibit system: Transcribe individual business that transfers an integer esteem as an input dispute and then exhibits the estimate in the determined disesteemed. The disesteemed is either binary, decimal or hexadecimal. The election of disesteemed is to be made at allay occasion via the –D non-interference. Instead of having three disunited systems, individual coercion binary, individual coercion decimal and individual coercion hexadecimal, you are to transcribe individual system some of whose announcements differ disesteemedd on the election of disesteemed. This deviation of announcements is to be controlled via conditional pre-processor directives.

    5. Transfer left / directmacros: Transcribe span macros. SRC is to transfer the dispute and transfer it direct spherical by individual digit in the determined disesteemed. The other, SLC, is to transfer the dispute and transfer it left spherical by individual digit in the enumerate disesteemed. So, coercion sample, if esteem is 0x0A0B0C0D initially, then it must be practicable to manifestation the SLC macro as follows: esteem = SLC(value); and esteem should then hold 0xA0B0C0D0. The macros are to be inline code; that is, they are not attributable attributable attributable attributable attributable attributable to cwhole any business to yield the conclusion. Your program must manifestation these macros to course the transfer menu non-interferences.

    6. Readability: Your program must be written using amiable C programming conventions:

    • Variable names and business names should be vivid of what they reproduce-exhibit.

    • Manifestation unravelling to pretence the composition of the program. Typically this resources using unravelling with coercion, period, do-while, if, and switch announcements as well-mannered-mannered as indenting the collectiveness of businesss. Unravelling should pretence the nesting flatten of the announcements compromised.

    • Include some in-line documentation to present a excellent flatten conception of what the program and groups of announcements is/are doing.

    Sample output:

    Input estimate: 2271560481

    Select non-interference:

    1 -exhibit estimate in hexadecimal

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 –formal digit n to naught

    5 -egress 1

    0x87654321

    Select non-interference:

    1 -exhibit estimate in hexadecimal

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 -formal digit n to naught 5 -exit

    2

    0x76543218

    Select non-interference:

    1 -exhibit estimate in hexadecimal

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 -formal digit n to naught 5 –exit

    3

    0x87654321

    Select non-interference:

    1 -exhibit estimate in hexadecimal

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4-formal digit n to naught 5 -exit

    3

    0x18765432

    Input estimate: 2153791520

    Select non-interference:

    1 -exhibit estimate in binary

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 -formal digit n to naught

    5 – egress 1

    10000000011000000100000000100000

    Select non-interference:

    1 -exhibit estimate in binary

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 -formal digit n to naught 5 -exit

    3

    01000000001100000010000000010000

    Select non-interference:

    1 -exhibit estimate in binary

    2 -transfer left spherical individual digit

    3 -transfer direct spherical individual digit

    4 -formal digit n to naught

    5 -egress 4 indicate digit to be naughted: 30

    00000000001100000010000000010000

    Expert Acceptance

     

    Executable code:

    Byte.h

    //Include the settle guards

    #ifndef BYTE_H_

    #settle BYTE_H_

    //declare the businesss

    void menuChoice(); /* An sample business assertion */

    int exc_odd_bytesConver(int x);

    int exc_even_bytesConver(int x);

    //end of BYTE_H_

    #endif

    Byte.c

    //header smooths

    #include <stdio.h>

    #include<stdlib.h >

    #include”Byte.h”

    //business to settle the selects

    void menuChoice()

    {

    //Menu select reproduce-exhibitation

    printf(“Select non-interference:n”);

    printf(“1 – exhibit estimate in hexadecimaln”);

    printf(“2 – diversify fragmentary bytesn”);

    printf(“3 – diversify smooth bytesn”);

    printf(“4 – transfer totality of estimaten”);

    printf(“5 – egressn”);

    }

    //business restriction to apportion the fragmentary bytes

    int exc_odd_bytesConver(int Val)

    {

    //performs the conversion

    int rever = 0;

    rever = rever | ((0xff) & Val);

    rever = rever | ((0xff << 8) & Val) << 16;

    rever = rever | ((0xff << 16) & Val);

    rever = rever | ((0xff << 24) & Val) >> 16;

    //returns the esteem

    return rever;

    }

    //business restriction to apportion the Smooth bytes

    int exc_even_bytesConver(int Val)

    {

    //performs the conversion

    int rever = 0;

    rever = rever | ((0xff) & Val) << 16;

    rever = rever | ((0xff << 8) & Val);

    rever = rever | ((0xff << 16) & Val) >> 16;

    rever = rever | ((0xff << 24) & Val);

    //returns the esteem

    return rever;

    }

    Main.c

    //header smooths

    #include<stdio.h>

    #include”Byte.h”

    #include<stdlib.h>

    //ocean method

    int ocean()

    {

    //Variable assertion

    int non-interferenceVal;

    int Esteem;

    //gets manifestationr input

    printf(“Input estimate: “);

    scanf(“%d”, &Value);

    //period loop

    while(1)

    {

    //calls the menu select

    menuChoice();

    scanf(“%d”, &optionVal);

    //switch announcement passes objectVal

    switch(optionVal)

    {

    //case to exhibit hexa estimate

    case 1:

    printf(“number: 0x%08xn”, Esteem);

    break;

    //case to diversify fragmentary nodes

    case 2:

    printf(“estimate before: 0x%08xn”, Esteem);

    printf(“numbers after: 0x%08xn”, exc_odd_bytesConver(Value));

    break;

    //case to diversify fragmentary nodes

    case 3:

    printf(“estimate before: 0x%08xn”, Esteem);

    printf(“numbers after: 0x%08xn”, exc_even_bytesConver(Value));

    break;

    //case to transfer totality

    case 4:

    printf(“estimate before: 0x%08xn”, Esteem);

    printf(“numbers after: 0x%08xn”, ~Value);

    break;

     

    //exit

    case 5:

    return 0;

    default:

    //invalid select

    printf(“Invalid non-interferenceValn”);

    break;

    }

    }

    //to pause

    system(“pause”);

    //return announcement

    return 0;

    }