Question
Purpose: The objective of this project is to gain experience with C language preprocessor directives(# define) and bit-wise operators. Requirements: The assignment centers around an
Purpose:
The objective of this project is to gain experience with C language preprocessor directives(# define) and bit-wise operators.
Requirements:
The assignment centers around an integer whose digits are to be reversed. The interpretation of what is a digit is to be based on whether a compile-time option specifies that binary or hexadecimal digits are to be used. Whenever possible you must make use of bit-wise operators (not arithmetic operators).
main routine:
The main routine is to be structured as follows: set number based on compile-time selection (see item 4.c below).
for each digit in the number:
extract digit from number
insert into reversed number
Display original number and reversed number in binary or hexadecimal; see item 4.d below.
perform another reversal of the reversed number and verify that the second number matches the original number.
Except for perhaps a function to display numbers to a specified base, main is not to use functions that you write, but must use macros as explained below.
4. macros: You must write and use several macros to accomplish this project;
a. Write one macro to extract a digit from the number. This macro must work for both binary digits and hexadecimal digits.
b. Write one macro to insert a digit into the reversed number. This macro must work for both binary digits and hexadecimal digits.
c. Use a #define to specify the selected number. It must be possible to select one of the following three numbers without editing the program or inputting values into the program at runtime. The three numbers are:
0x13579BDF, -65536, and 100.
d. Use the D option on the cc-command to specify whether digits are to be base 2 or base 16; the default is base 16. This option also specifies
whether the output is to be base 2 or base 16. That is, the output is to correspond to the base in which the digits are interpreted. The macros must neither call a function that you create, nor a library function.
OUTPUT
Sample output: # cc -DONE -o rev rev.c
# ./rev
Original number: 0x13579BDF
Reversed number: 0xFDB97531
Second reverse: 0x13579BDF
Reversing reversed number yields original number
# cc -DBIN -DTHREE -o rev rev.c # ./rev
Original number: 00000000000000000000000001100100
Reversed number: 00100110000000000000000000000000
Second reverse: 00000000000000000000000001100100
Reversing reversed number yields original number
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