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");
scanf("%d",&n);
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

What is the difference between array_name and &array_name?

0 Answers  


Why do we need a structure?

0 Answers  


What is New modifiers?

0 Answers   NA,


Explain function pointer with exapmles.

2 Answers  


why in C,C++'s int size is 2 byte and .net(c#) int Size is 4 byte?

2 Answers  






Hi Every one...........I have been selected for the SBI Clerk. But i m one month Pregnanat. So anyone please suggest me, is they take any objection on my joining .

4 Answers   State Bank Of India SBI,


#include<std.h> int main() { char *str[]={"Frogs","Do","Not","Die","They","Croak!"}; printf("%d %d\n",sizeof(str),strlen(str)); ...return 0; } what will the output of the above program?

6 Answers  


What are the different types of objects used in c?

0 Answers  


When should the const modifier be used?

0 Answers  


Describe advantages and disadvantages of the various stock sorting algorithms

1 Answers   Microsoft,


what is difference between array and structure?

44 Answers   College School Exams Tests, CTS, Google, HCL, IBM, Motorola, TCS,


what is the coding of display the factorial of a number using array and function?

1 Answers  


Categories