how to set Nth bit of variable by using MACRO

Answer Posted / kirankumaryakkala

#define set(val,n) val|=1<<n //do left-shift then bitwise OR

logic is val|=1<<n
means,
first shift the value 1 to ntimes and do the bitwise or with
value.
u will get the answer

Is This Answer Correct ?    30 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What the different types of arrays in c?

606


What are the advantages of using linked list for tree construction?

634


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

641


How to write c functions that modify head pointer of a linked list?

534


What is variable in c example?

583






What is the difference between new and malloc functions?

568


Write a program to print "hello world" without using a semicolon?

587


Discuss the function of conditional operator, size of operator and comma operator with examples.

666


Is a pointer a kind of array?

589


How will you write a code for accessing the length of an array without assigning it to another variable?

607


Which of these functions is safer to use : fgets(), gets()? Why?

626


What is operator precedence?

636


What is sizeof in c?

560


What are c preprocessors?

664


Why do we need a structure?

578