CopyBits(x,p,n,y)
copy n LSBs from y to x starting LSB at 'p'th position.

Answer Posted / vadivel t

Hi,
Small bug is there in the above code, which i have posted.
But the same has been resolved here.

#include<stdio.h>
#include<conio.h>

int main()
{
int x, y, n , p, i, j, temp;
printf("ENTER X, Y, NO OF BITS AND BIT POSITION: \n");
scanf("%d %d %d %d",&x, &y, &n, &p);
for(i = p, j = 0; i < n+p; i++, j++)
{
if(x & (0x01 << i-1))
x = x^(0x01 << i-1);
temp = y & (0x01 << j) ? 1 : 0;
x = x | (temp << i-1);
}
printf("VALUE OF X:%d \n",x);
getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

628


If the size of int data type is two bytes, what is the range of signed int data type?

596


What is p in text message?

542


Discuss the function of conditional operator, size of operator and comma operator with examples.

682


What is boolean in c?

615






How can you determine the size of an allocated portion of memory?

748


What is the use of header?

626


Write the Program to reverse a string using pointers.

620


Can a pointer be static?

627


Write a program to swap two numbers without using third variable?

817


What is strcpy() function?

660


What is a char in c?

559


what are bit fields in c?

609


What do the functions atoi(), itoa() and gcvt() do?

726


How will you write a code for accessing the length of an array without assigning it to another variable?

618