What is bit?
A computer is a collection of switches that has either on
and off
.
Each switch represents one binary digit, commonly known as a 'bit.
byte`.
A single switch is referred to as one bit.
Generally, this switch is operated with eight bits and this eight switched is called as
What it bit operations?
Bit Operations control on/off switching of switches.
There are many operations to adopt to many situations.
On/off control is done in units of bytes.
Bit Operations
&(AND)
Compares two switches and returns 1 if both are 1 and 0 if either is 0.
It is used to search whether flag is set.
example
a: 11110000
b: 10101010
↓
c: 10100000
|(OR)
Compares two switches and returns 1 if either is 1 and 0 if both are 0.
It is used to set flag.
example
a: 11110000
b: 10101010
↓
c: 11111010
!(NOT)
It is shown as ^
.
Inverts all on/off state of switches, changing 0 to 1 and 1 to 0.
example
a: 11110000
↓
b: 00001111
^(XOR)
Compares two switches and returns 1 if either is 1 and 0 if both are 0 or 1.
It is used to search where is difference.
examples
a: 11110000
b: 10101010
↓
c: 01011010
>>(Right bit shift)
Shift the state of on/off of switches to right.
0 is entered in the empty frame by shifting, and if it protrudes from the determined number of digits, it disappears.
Disappears when it overflows is called overflow, and it is used when performing bit manipulation using a loop.
examples
c = a >> 1
a: 11110000
↓
c: 01110000
<<(Left bit shift)
Shift the state of on/off of switches to left.
example
c = a << 1
a: 11110000
↓
c: 11100000
Summarise
By combining these, we can do computer-specific calculations that can't be done with +
, -
, *
, and /
.
We can calculate specificatte computer
Top comments (0)