write a c program to check weather a particluar bit is set
or not?
Answer Posted / abdur rab
#include <stdio.h>
int main ()
{
int variable = 6;
int position = 3;
char array [2][10] = {"NOT SET", "SET"};
// check the wheather the second bit is set
printf ( "\n The bit is %s",
array [ ( variable & ( 1 << (
position - 1 ) ) ) / position ] );
return ( 0 );
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
What is the value of h?
How can I delete a file?
The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
Why is c called "mother" language?
show how link list can be used to repersent the following polynomial i) 5x+2
Are there constructors in c?
What is calloc malloc realloc in c?
Explain what is the benefit of using #define to declare a constant?
What is equivalent to ++i+++j?
Which is best linux os?
How can I remove the leading spaces from a string?
Is a pointer a kind of array?
What is the purpose of sprintf() function?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?