Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

how to set Nth bit of a variable?

how to set Nth bit of a variable?..

Answer / kirankumaryakkala

ex: int res=16, temp=1,n;
printf("enter the Nth bit no");
temp=temp<<n; //leftshift to ntimes
res=res|temp; //bitwise OR
printf("setted nth bit of res %d",res);

Is This Answer Correct ?    9 Yes 4 No

Post New Answer

More C Interview Questions

write C code to reverse a string such that if i/p is "abc defg hij klmno pqrs tuv wxyz" and the o/p should be "cba gfed jih onmlk srqp vut zyxw"

2 Answers  

write a c programme for add of two numbers with out use of arthematic operators

2 Answers  

Why c is called a middle level language?

0 Answers  

what is default constructor?

2 Answers   HCL,

Why doesn't C have nested functions?

2 Answers  

Is null a keyword in c?

0 Answers  

can any one tell that i have a variable which is declared as static but i want this variable to be visible to the other files? how?

2 Answers  

Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

0 Answers  

What is c value paradox explain?

0 Answers  

21. #define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

3 Answers  

how can f be used for both float and double arguments in printf? Are not they different types?

0 Answers  

Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

0 Answers   Huawei,