Bitwise operators
1. AND (&)
2. OR (|)
3. X-OR (^)
4. Compliment (~)
5. Shift Left (<<)
6. Shift Right (>>)
AND &:
If both binary digit is 1, then output of "bitwise and" (&) will be 1
Example 1
Bit Operation of 10 and 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
8 0000 1000
********************************
Example 2:
Bit Operation of 20 and 21
20 0001 0100
21 0001 0101
------------------------------
16 0001 0100
*********************************
OR | :
If either one of binary digit is 1, then output of "bitwise OR" (|) will be 1
Example 1
Bit Operation of 10 OR 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
27 0001 1011
********************************
Example 2:
Bit Operation of 20 OR 21
20 0001 0100
21 0001 0101
------------------------------
21 0001 0101
*********************************
XOR ^ :
If the digit or opposite, then output of "bitwise XOR" (^) will be 1
Example 1
Bit Operation of 10 OR 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
19 0001 0011
********************************
Example 2:
Bit Operation of 20 OR 21
20 0001 0100
21 0001 0101
------------------------------
1 0000 0001
*********************************
1. AND (&)
2. OR (|)
3. X-OR (^)
4. Compliment (~)
5. Shift Left (<<)
6. Shift Right (>>)
AND &:
If both binary digit is 1, then output of "bitwise and" (&) will be 1
Example 1
Bit Operation of 10 and 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
8 0000 1000
********************************
Example 2:
Bit Operation of 20 and 21
20 0001 0100
21 0001 0101
------------------------------
16 0001 0100
*********************************
OR | :
If either one of binary digit is 1, then output of "bitwise OR" (|) will be 1
Example 1
Bit Operation of 10 OR 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
27 0001 1011
********************************
Example 2:
Bit Operation of 20 OR 21
20 0001 0100
21 0001 0101
------------------------------
21 0001 0101
*********************************
XOR ^ :
If the digit or opposite, then output of "bitwise XOR" (^) will be 1
Example 1
Bit Operation of 10 OR 15
Decimal Binary
10 0000 1010
25 0001 1001
------------------------------
19 0001 0011
********************************
Example 2:
Bit Operation of 20 OR 21
20 0001 0100
21 0001 0101
------------------------------
1 0000 0001
*********************************
No comments:
Post a Comment