C++ Programming Blog

 
 
 

Image

 # include <iostream.h>
 # include    <conio.h>

 void binary_code(int);

 void main( )
    {
       clrscr( );
       textmode(BW80);

       int a;
       int b;
       int c;

       cout<<\"\\n Enter the value of a = \";
       cin>>a;

       cout<<\" Enter the value of b = \";
       cin>>b;

       c=(a|b);

       cout<<\"\\n The Bitwise OR of a and b = a|b = \"<<(c);

       cout<<\"\\n\\n\\n The Binary code of a   = \";
       binary_code(a);

       cout<<\"\\n The Binary code of b   = \";
       binary_code(b);

       cout<<\"\\n\\n The Binary code of a|b = \";
       binary_code(c);

       getch( );
    }


 //---------------------------  binary_code( )  --------------------------//


 void binary_code(int number)
    {
       int remainder;
       int qutiont;

       int count=0;
       int x=(wherex( )+16);
       int y=wherey( );

       if(number>0)
      {
         while(number>0)
        {
           qutiont=number/2;
           remainder=number%2;
           number=qutiont;

           gotoxy((x-count),y);
           cout<<remainder;

           count++;
        }
      }

       else
      {
         gotoxy((x-count),y);
         cout<<\"0\";
      }
    }

 
 
Didn't find what you were looking for? Find more on Program to show the use of Bitwise operator OR ( | )