[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Bitwise Operator

Home > Programs > Bitwise Operator

16 / 15

Write an efficient program to toggle all bits in a given integer number

Answer:

#include 
#include
using namespace std;
int main()
{
    int num, n, newNum;
    /*Reads a number from user*/
   coutnum; 
    /*Reads the bit number you want to toggle*/
    coutn; 
    /* Left shifts 1 to n times then perform bitwise XOR with number and result of above*/
    newNum = num ^ (1 

Asked In ::

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: