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

write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.

3 Answers  


What is malloc calloc and realloc in c?

0 Answers  


What is advantage of pointer in c?

0 Answers  


Can we declare variable anywhere in c?

0 Answers  


Where can I get an ansi-compatible lint?

0 Answers  


How can a program be made to print the name of a source file where an error occurs?

0 Answers  


Given a number N, product(N) is the product of the digits of N. We can then form a sequence N, product(N), product(product(N))… For example, using 99, we get the sequence 99, 99 = 81, 81 = 8. Input Format: A single integer N Output Format: A single integer which is the number of steps after which a single digit number occurs in the sequence. Sample Test Cases: Input #00: 99 Output #00: 2 Explanation: Step - 1 : 9 * 9 = 81 Step - 2 : 8 * 1 = 8 There are 2 steps to get to this single digit number. Input #01: 1137638147

2 Answers  


what is real time system?what is the differance between hard and soft real time systems

2 Answers  


can we declare a function in side the structure?

2 Answers   HCL,


Efficient data structure for store/search list of 1000 records a)array b)double linked list c)circular queue d)hash table

3 Answers   Value Labs,


Why doesn't the code "a[i] = i++;" work?

4 Answers  


Can you think of a way when a program crashed before reaching main? If yes how?

2 Answers  


Categories