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 meaning When we write "#include" what is # and what does include does there???

22 Answers   HCL, Wipro,


Can a variable be both static and volatile in c?

0 Answers  


What is the use of pointers in C?

0 Answers   Impetus, Motorola, Tavant Technologies, Virtusa,


write a program which counts a product of array elements lower than 10.

1 Answers  


write a c program to calculate the income tax of the employees in an organization where the conditions are given as. (I.T. = 0 if income <100000 I.T = 10% if income _< 200000 it = 20% if income >_ 200000)

7 Answers   Consultancy, DBU, FD, JK Associates, Kobe, Satyam,






how to write hello word without using semicolon at the end?

6 Answers   Accenture,


How do c compilers work?

0 Answers  


Are enumerations really portable?

0 Answers  


how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .

1 Answers  


How to swap 3 numbers without using 4th variable?

5 Answers  


25. It takes five minutes to pass a rumour from one person to two other persons. The tree of rumour continues. Find how many minutes does it take spread the rumour to 768 persons. ?

11 Answers   CTS, TCS,


What is auto keyword in c?

0 Answers  


Categories