Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your program should have test cases in the main function. Note: Do not use arrays to store the binary representation of the input and /

Your program should have test cases in the main function.
Note: Do not use arrays to store the binary representation of the input and/or output
numbers. Arrays require extra memory space which can be avoided by using bitwise
operations on variables directly. Since this is a bit manipulation exercise, using arrays is
not allowed. Using arrays is inefficient for this problem and also makes the problem
trivial.
Combine bits from two integers x and y. Assume both are unsigned integers (data type is
unsigned int x,y). The C function should return an unsigned int as well as an answer.
Example:
x=0x8 in hex and x=1000 in binary
y=0x6 in hex and x=0110 in binary
z is the answer after combining bits from x and y.
The figure below also shows the how bits from x and y are combined to get bits in z.
Z= combine (x,y)= combine (8,6)=01101000=104 in decimal.
Test case: The inputs x and y should be less than 65,535.
x=101 and y=123
x=99 and y=71
Hint: Looking at the bits at different bit positions, you can see that the bits are getting shifted in order to combine them.
Unsigned number example:
int main()
{
unsigned int a=63;
printf(a =%u
, a);
printf(Enter b ln);
unsigned int b;
scanf("%u", &b);
printf(You entered %u In, b);
}
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What are two advantages of high coordination in a GIS environment?

Answered: 1 week ago

Question

\f

Answered: 1 week ago