Pengertian Operator bitwise
Cara membuat kaklulator Bitwise pada C++ adalah sebagai berikut :
1.Buatlah file dengan nama bitwise.cpp
2.Salinlah kode program di bawah ini
#include <iostream>
using namespace std;
int main()
{
cout <<"OPRATOR BITWISE"<<endl<<endl;
cout <<"Shift Right = <"<<endl;
cout <<"Shift Letf = >"<<endl;
cout <<"AND = &"<<endl;
cout <<"OR = |"<<endl;
cout <<"NOT = ~"<<endl;
cout <<"XOR = ^"<<endl<<endl;
//DEKLARASI
int a,b,d,hasil;
char c;
cout <<"A = ";
cin >>a;
cout <<"OPRATOR = ";
cin >>c;
//Shift Right
if (c == '>'){
cout <<"Geser Berapa Kali = ";
cin >>d;
hasil=a>>d;
cout <<a<<" >> "<<"="<<hasil<<endl<<endl;}
//Shift Letf
else if (c == '<'){
cout <<"Geser Berapa Kali = ";
cin >>d;
hasil=a<<d;
cout <<a<<" <<"<<" = "<<hasil<<endl<<endl;}
//AND
else if (c == '&'){
cout <<"B = ";
cin >>b;
hasil=a&b;
cout <<a<<c<<b<<" = "<<hasil<<endl<<endl;}
//OR
else if (c == '|'){
cout <<"B = ";
cin >>b;
hasil=a|b;
cout <<a<<c<<b<<" = "<<hasil<<endl<<endl;}
//XOR
else if (c == '^'){
cout <<"B = ";
cin >>b;
hasil=a^b;
cout <<a<<c<<b<< " = " <<hasil<<endl<<endl;}
//NOT
else if (c == '~'){
hasil=~a;
cout <<a<<c<<" = "<<hasil<<endl<<endl;}
//JIKA TIDAK TERPENUHI
else {
cout <<"OPRATOR KAMU SALAH!!!"<<endl<<endl;}
cout <<"AKHIR DARI PROGRAM"<<endl;
cin.get();
return 0;
}
3. Pastekan pada file bitwise.cpp
4. Jangan lupa simpan terlebih dahulu
5. Run file bitwise.cpp
Contoh hasil run file bitwise.cpp
Hasil Eksekusi :
Shift Right = <
Shift Letf = >
AND = &
OR = |
NOT = ~
XOR = ^
A = 10
OPRATOR = &
B = 12
10&12 = 8
AKHIR DARI PROGRAM
Shift Right = <
Shift Letf = >
AND = &
OR = |
NOT = ~
XOR = ^
A = 10
OPRATOR = &
B = 12
10&12 = 8
AKHIR DARI PROGRAM
Shift Right = <
Shift Letf = >
AND = &
OR = |
NOT = ~
XOR = ^
A = 17
OPRATOR = >
Geser Berapa Kali = 1
17 >> =8
AKHIR DARI PROGRAM
Artikel Terkait :
Refrensi : https://www.belajarcpp.com/
0 Reviews:
Posting Komentar