Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a MENU DRIVEN program in c language to 1) Print the binary conversion of a number 2) Convert a target bit to 1 of

Write a MENU DRIVEN program in c language to

1) Print the binary conversion of a number

2) Convert a target bit to 1 of the number passed

3) Extract the specific byte from a given number

4) Generate the new number as mentioned

0) Exit the program

The program should start with a user prompt to enter an integer number.

Option A will print the binary equivalent of the decimal number entered.

Prototype : void printBinary(int);

Option B will set the target bit of an integer to 1, and returns the new value. For example, when integers x and y are given to the function, the yth bit (from the right side ) in x should be set to 1. Note that y should be between 0 and 31 inclusively.

Prototype : int convertBit(int, int );

(Call printBinary with the returned number to validate)

Option C extracts a certain byte (1 to 4 from right to left) from a given integer and returns the extracted byte as an integer. For example, when two integers x and 2 are passed to the function, the function returns the 2nd byte from x.

Prototype : int extractByte(int, int );

Option D creates a new number with a certain number of bits to 1 and all the other bits to 0. The value should be returned from the function. For example, when integers x = 3 (3rd from right) and y = 8 (number of 1s) are passed to the function, the function should return the integer that has a binary number of 00000000 00000000 00000111 11111000.

Prototype : int generateNumber(int, int );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions