Bitwise Operators between Negative Numbers in C++

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Program for Bitwise operator for -ive number
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
        int a;
        clrscr();
         a=((-9&6)^-5)|-7;
         cout<<a;

}


  /* 
  1100
  0011
       1
--------
  0100














           0101    5

    1s    1010  
    2s       +1
   -------------
          1011    -5
          0110     6
       &
       ----------
          0010    2

      1111  1011    -5
      0000   0110     6
       |  
 ------------------------
    11111111111111111

  */

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *