Embedded systems and linux device driver interview questions
For the first question to find if the number is a power of 2 or not, an ! is missing in the if statement. Reason: If a number is a power of 2, then the bit wise and of the number with number - 1 would result in all zeros.
Good Point. Agreed.
This comment has been removed by the author.
For the question "Write a function to swap even bits with consecutive odd bits in a "number.following should be the answer.return (num<<1 & 0x55555555) | (num>>1 & 0xAAAAAAAA);
int power_of_two(unsigned int number){ if((number)&(number-1)) printf("%d Not Power of two\n",number); else printf("%d Power of two\n",number);return 0;}
GoodHere is blog for basic C and C++ programs List of C and C++ Programsblog link C and C++ based programs
The links are not not working anymore !!
For the first question to find if the number is a power of 2 or not, an ! is missing in the if statement.
ReplyDeleteReason: If a number is a power of 2, then the bit wise and of the number with number - 1 would result in all zeros.
Good Point. Agreed.
DeleteThis comment has been removed by the author.
ReplyDeleteFor the question "Write a function to swap even bits with consecutive odd bits in a "number.
ReplyDeletefollowing should be the answer.
return (num<<1 & 0x55555555) | (num>>1 & 0xAAAAAAAA);
int power_of_two(unsigned int number){
ReplyDeleteif((number)&(number-1))
printf("%d Not Power of two\n",number);
else
printf("%d Power of two\n",number);
return 0;
}
Good
ReplyDeleteHere is blog for basic C and C++ programs
List of C and C++ Programs
blog link
C and C++ based programs
The links are not not working anymore !!
ReplyDelete