Monday, August 13, 2012

Interview questions on Bitwise Operators

1)Which bit wise operator is suitable for turning off a particular bit in a number?

2)what will be printed out when the following code is executed:

main()
{
printf("%x",-1<<4);
}

3)Which one is equivalent to multiplying by 2?

* Left shifting a number by 1
* Left shifting an unsigned int or char by 1?

4)Write a function which gets the n bits from an unsigned integer x, starting from position p .(the right most digit is at position 0)

5)Write a function using bitwise opetators to check whether an integer is a power of 2 or not?

6)Write a Program that swaps the contents of two variables without
using any other variable,using bitwise operators?

7) Which bit wise operator is suitable for checking whether a particular bit is on or off?

8) Which bit wise operator is suitable for putting on a particular bit in a number?

9) Which bit wise operator is suitable for checking whether a particular bit is on or off?

10)Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y,leaving the other bits changed.

11)Write a function invert(x,p,n) that returns x with the n bits that begin at position p inverted leaving other unchanged

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...