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.

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

Thank you for such a wonderful Information !! Here is a list of Top LINUX INTERVIEW QUESTIONSSAMBA Server Interview QuestionsLinux FTP vsftpd Interview QuestionsSSH Interview QuestionsApache Interview QuestionsNagios Interview questionsIPTABLES Interview QuestionsLdap Server Interview QuestionsLVM Interview questionsSendmail Server Interview QuestionsYUM Interview QuestionsNFS Interview QuestionsRead More at :- Linux Troubleshooting

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.

DeleteAgreed

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

Thank you for such a wonderful Information !!

ReplyDeleteHere is a list of Top LINUX INTERVIEW QUESTIONS

SAMBA Server Interview Questions

Linux FTP vsftpd Interview Questions

SSH Interview Questions

Apache Interview Questions

Nagios Interview questions

IPTABLES Interview Questions

Ldap Server Interview Questions

LVM Interview questions

Sendmail Server Interview Questions

YUM Interview Questions

NFS Interview Questions

Read More at :- Linux Troubleshooting

The links are not not working anymore !!

ReplyDelete