Question: A16 - WAP to replace 'n' bits of a given number Available from : Friday, 18 March 2022, 12:57 PM Due date : Monday, 6

A16 - WAP to replace 'n' bits of a given number

Available from: Friday, 18 March 2022, 12:57 PM Due date: Monday, 6 May 2024, 11:59 PM Requested files: replace_nbits.c ( Download) Type of work: Individual work Reduction by automatic evaluation: 10 Free evaluations: 10

Description:

a. Read number num from user. b. Read number n from user. c. Read number val from user d. Fetch n number of bits from LSB end of val and replace in the last n bits of num. e. Return new value of num. If num is 10 and n is 3 and val is 12 10 -> 0 0 0 0 1 0 1 0 12 -> 0 0 0 0 1 1 0 0 The program should print result as 12 (1 1 0 0)

Pre-requisites:

Bitwise operators

Functions

Sample Execution:

Test Case 1:

Enter the number: 10

Enter number of bits: 3

Enter the value: 12

Result = 12

Test Case 2:

Enter the number: 15

Enter number of bits: 2

Enter the value: 1

Result = 13

Assignment slide : https://moodle.emertxe-group.com/pluginfile.php/189828/mod_vpl/intro/02_replace_n_bits.pdf

A16 - WAP to replace 'n' bits of a given number

Available from: Friday, 18 March 2022, 12:57 PM Due date: Monday, 6 May 2024, 11:59 PM Requested files: replace_nbits.c ( Download) Type of work: Individual work Reduction by automatic evaluation: 10 Free evaluations: 10

Description:

a. Read number num from user. b. Read number n from user. c. Read number val from user d. Fetch n number of bits from LSB end of val and replace in the last n bits of num. e. Return new value of num. If num is 10 and n is 3 and val is 12 10 -> 0 0 0 0 1 0 1 0 12 -> 0 0 0 0 1 1 0 0 The program should print result as 12 (1 1 0 0)

Pre-requisites:

Bitwise operators

Functions

Sample Execution:

Test Case 1:

Enter the number: 10

Enter number of bits: 3

Enter the value: 12

Result = 12

Test Case 2:

Enter the number: 15

Enter number of bits: 2

Enter the value: 1

Result = 13

C PROGRAM i need exact output for this program

A16 - WAP to replace 'n' bits of a given num

Description:

a. Read number num from user. b. Read number n from user. c. Read number val from user d. Fetch n number of bits from LSB end of val and replace in the last n bits of num. e. Return new value of num. If num is 10 and n is 3 and val is 12 10 -> 0 0 0 0 1 0 1 0 12 -> 0 0 0 0 1 1 0 0 The program should print result as 12 (1 1 0 0)

Pre-requisites:

Bitwise operators

Functions

Sample Execution:

Test Case 1:

Enter the number: 10

Enter number of bits: 3

Enter the value: 12

Result = 12

Test Case 2:

Enter the number: 15

Enter number of bits: 2

Enter the value: 1

Result = 13

#include

int replace_nbits(int, int, int);

int main() { int num, n, val, res = 0; printf("Enter num, n and val:"); scanf("%d%d%d", &num, &n, &val); res = replace_nbits(num, n, val); printf("Result = %d ", res); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!