Toggle nth bit in a given integer - num

Answer Posted / vadivel t

#include<stdio.h>

int main()
{
int no, bit;
printf("ENTER THE NO AND BIT NO, TO TOGGLE: ");
scanf("%d %d", &
no, &bit);
if(no & (0x1 << bit-1))
{
no = no^(0x1 << bit - 1);
}
else
{
no = no | (0x1 << bit - 1);
}
printf("%d \n", no);

_getch();
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does calloc stand for?

659


Can include files be nested? How many levels deep can include files be nested?

666


What is the explanation for cyclic nature of data types in c?

659


How to write a multi-statement macro?

631


Can we assign string to char pointer?

600






Explain how can you avoid including a header more than once?

609


What is c mainly used for?

607


What are the two forms of #include directive?

653


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

681


1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.

2345


What is the use of c language in real life?

542


What is cohesion in c?

549


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

693


What is define c?

585


What do you mean by keywords in c?

640