how to set Nth bit of variable by using MACRO

Answer Posted / sunitha

/* macro to set Nth bit */

#define SET_N_BIT(x,n) x|((~(unsigned)0)>>(8-(n-n-1))<<n);

Try out this . this is optimised version for setting a bit
work for any bit upto 8 bits if u want for 32 bits than
replace 8 with 32.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c token?

611


Explain built-in function?

593


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

708


How can you check to see whether a symbol is defined?

592


Do you know the difference between malloc() and calloc() function?

616






Write a program for finding factorial of a number.

636


write a program to display all prime numbers

1456


Simplify the program segment if X = B then C ← true else C ← false

2587


What is New modifiers?

671


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

4842


Write a program to swap two numbers without using a temporary variable?

611


What is the purpose of the statement: strcat (S2, S1)?

642


about c language

1606


What is the difference between functions abs() and fabs()?

651


What is the difference between a function and a method in c?

561