Bitwise operators can only be imposed on the operator operands of type integer and character. The usefulness of these operators include access to individual bits in memory. Oerator bitwise have a lower priority than arithmetic operators.
Operator>> and <<is useful to shift the bits into an integer to the left or right. Shift bits to the left have the effect of such multiplication, while giving effect to the right such as the division.
To kebih details, note the following syntax. I will include six bitwise operators together in one program.
#include "conio.h"
main()
{
unsigned char x = 93;
unsigned char y = 93;
unsigned char a, b, c, d;
unsigned char nilai1 = 81;
unsigned char nilai2 = 99;
clrscr();
//pergeseran kekiri
cout<<"Nilai X sebelum digeser : "<<
x = x << 1; //geser ke kiri 1 bit
cout<<"Nilai X setelah digeser "<<
//pergeseran kekanan
cout<<"Nilai Y sebelum digeser : "<<
y = y >> 1;//geser kekanan 1 bit
cout<<"Nilai Y setelah digeser : "<<
//operasi atau, dan, XOR
a = nilai1 | nilai2; //operasi atau
b = nilai1 & nilai2; //operasi dan
c = nilai1 ^ nilai2; //operasi XOR
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
cout<<"c = "<<c<<endl;
//komplemen
d = ~nilai1; //komplemen dari nilai1
cout<<"Nilai1 Setelah dikomplemen : "<<d<<endl;
getch();
}
No comments:
Post a Comment