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

To what value are pointers initialized? 1) NULL 2) Newly allocated memory 3) No action is taken by the compiler to initialize pointers.

4 Answers   Aricent,


What is New modifiers?

0 Answers   NA,


Differentiate between new and malloc(), delete and free() ?

0 Answers   iNautix,


1. Write a c pgm to print 1 to 100 without using loops. 2. Write a c pgm for leap year 3. Write a c pgm fibbonacci series,factorial 4. Write a c pgm count no of lines , blanks, tabs in a para(File concept) 5. Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6.how do get the o/p in number from 1 to 100 in the screen without using control statement? 7. who do u print the word "hello world" without using "printf" statement? 8. write sql program to get the detail of student in a class? Definitions: structure union arrays linkedlist macros directives difference b/w pre processorsDiffrence: 1.Constructors and destructors 2.Structure and Union 3.Array and Lists 4.pre processor... 5. Privillages in C++ 6.structure and union 7.break and continue 8.while and dowhile Pgm..

3 Answers  


What is the scope of an external variable in c?

0 Answers  






Can main () be called recursively?

0 Answers  


What are structures and unions? State differencves between them.

0 Answers   iNautix,


How can I send mail from within a c program?

0 Answers  


Why c is known as a mother language?

0 Answers  


What is difference between Structure and Unions?

0 Answers   TISL,


WHY DO WE USE A TERMINATOR IN C LANGUAGE?

2 Answers  


What is the difference between far and near ?

0 Answers  


Categories