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 are the benefits of organizational structure?

562


What is a void * in c?

588


Differentiate between #include<...> and #include '...'

611


Explain how can I manipulate strings of multibyte characters?

769


What is data types?

626






What is the use of f in c?

548


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

1656


What are the application of void data type in c?

682


What does 3 periods mean in texting?

587


Can we assign integer value to char in c?

607


When should I declare a function?

613


How many data structures are there in c?

608


What is pointer to pointer in c with example?

540


Why is void main used?

607


What is the time and space complexities of merge sort and when is it preferred over quick sort?

665