Answer Posted / eswar.rajan89
#include<stdio.h>
void printbits(unsigned int a)
{
int i;
int b;
for(i=31;i>=0;i--)
{
b=(a>>i) & 1;
if(b == 1)
printf("1");
else
printf("0");
}
}
int find_bit(int end_bit,int start_bit, int value)
{
int x1,i;
int x2=0,x3=0,x4=0;
for(i=start_bit;i<end_bit;i++)
{
x1=(value>>i)&1;
x2=(x2<<1) | x1;
}
for(i=0;i<end_bit;i++)
{
x3=(x2>>i)&1;
x4=(x4<<1) | x3;
}
return x4;
}
int main()
{
int a,b,c,d,val,rep_bit,main_bit,conv_bit,c1_bit;
printf("\nEnter a number 'A' and 'B' \n");
scanf("%d %d",&a,&b);
printf("\nEnter a number 'C' and 'D' \n");
scanf("%d %d",&c,&d);
val=b-a+1;
rep_bit = find_bit(val,0,d);
c1_bit = find_bit(a,0,c);
main_bit = rep_bit<<a;
printf("\nThe bits before replacement are:\n");
printbits(c);
printf("\n");
printbits(main_bit);
printf("\n");
conv_bit= main_bit | c1_bit;
printf("\nThe bit after replacement is:\n");
printbits(conv_bit);
printf("\n");
printf("\n");
return 0;
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
Is c easier than java?
What does %p mean?
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
Write a code to determine the total number of stops an elevator would take to serve N number of people.
What is difference between && and & in c?
What are dangling pointers in c?
What does == mean in texting?
Describe the steps to insert data into a singly linked list.
List the difference between a 'copy constructor' and a 'assignment operator' in C?
What does s c mean in text?
Do you have any idea about the use of "auto" keyword?
Explain what is the difference between far and near ?
I heard that you have to include stdio.h before calling printf. Why?
What is difference between %d and %i in c?
How many levels of indirection in pointers can you have in a single declaration?