Operator Bitwise

OPERATOR BITWISE

// bitwise operator
#include <iostream>
using namespace std;

int main()
{
    int a = 39; // Memberikan nilai 39 pada variabel a
    int b = 14; // Memberikan nilai 14 pada variabel b
   
    int c = a & b; // Lakukan operasi AND
    cout << "Penggunaan operator AND (&)" << endl
         << "nilai a = " << a << endl
         << "nilai b = " << b << endl
         << "Nilai a & b = " << c << endl << endl;
        
    int d = a | b; //Lakukan operasi OR
    cout << "Penggunaan Operasi OR (|)" << endl
         << "Nilai a = " << a << endl
         << "Nilai b = " << b << endl
         << "Nilai a | b = " << d << endl << endl;
        
    int e = a ^ b; // lakukan operasi XOR
    cout << "Pengunaan operasi XOR (^)" << endl
         << "Nilai a = " << a << endl
         << "Nilai b = " << b << endl
         << "Nilai a ^ b = " << e << endl << endl;
        
    int f = ~a << 1; // Lakukan operasi NOT
    cout  << "Penggunaan Operasi NOT (~)" << endl
          << "Nilai a = " << a << endl
          << "Nilai ~a =" << f << endl << endl;
         
    int g = a << 1; // Lakukan Operasi SHL
    cout << "penggunaan Operasi SHL (<<)" << endl
         << "Nilai a = " << a << endl
         << "Nilai 1 << a = " << g << endl << endl;
   
    int h = a >> 1; //Lakukan Operasi SHR
    cout << "Penggunaan operasi SHR (>>)" << endl
         << "Nilai a = " << a << endl
         << "Nilai 1 >> a = " << h << endl << endl;
    system("PAUSE");
    return 0;
}


Ini hasilnya 



Bila Kurang jelas dengan struktur kode tersebut kalian bisa download materinya disini Download



0 komentar:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes