Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAM need same output donot give wrong and different prg 1 - WAP to put the (b-a+1) lsbs of num into val[b:a] Description: Read

C PROGRAM need same output donot give wrong and different prg

1 - WAP to put the (b-a+1) lsbs of num into val[b:a]

Description:

Read number num from user.

Read number val from user.

Read number a from user.

Read number b from user(a <= b <=31)

Do error checking

Check b is within limit or not.

Call replace_nbits_from_pos function by passing val, b - a + 1, b and n as arguments.

replace_nbits_from_pos(num, a, b, val);

Print the new value of i.

Prompt for continue option.

Example: If num = 11 = (0 0 0 0 1 0 1 1) 2 val = 174 = (1 0 1 0 1 1 1 0) 2 a = 3, b = 5 No_of_bits = b a + 1 = 5 3 + 1 = 3, get 3 bits from 11(num) and replace 3(No_of_bits)from 5th(b) postion of 174(val) then New 'val' value = (1 0 0 1 1 1 1 0) 2 = 158

Pr-requisites:-

Bitwise Operators

Functions

Objective: -

To understand the concept of

Functions

Bitwise Operators

Inputs: - Integers num, val, a, b

Sample execution: - Test Case 1: Enter the value of 'num' : 11 Enter the value of 'a' : 3 Enter the value of 'b' : 5 Enter the value of 'val': 174 Result : 158

requested file

#include

int replace_nbits_from_pos(int, int, int, int);

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

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

Recommended Textbook for

More Books

Students also viewed these Databases questions