- : Bitwise Operator :-
Operators are those symbols which are used between operands to perform Mathematical and Logical operations.
Bitwise Operators are those operators which are used to perform operations on integer values at the bit-level. This Operator includes Following Symbols -
- Bitwise And [&]
- Bitwise Or [|]
- Bitwise XOR [^]
- Bitwise Complement Operator [~]
- Bitwise Left Shift Operator [<<]
- Bitwise Right Shift Operator [>>]
- Bitwise And (&) operator :-
2. Bitwise Or ( | ) Operator :-
if atleast one operand is "1", the output will be "1". if both operands are "0",the output will be "0".
A | B Output
1 1 1
1 0 1
0 1 1
0 0 0
For Example -
let A = 10 (in Decimal) = 1010 (in Binary)
B = 14 (in Decimal) = 1110 (in Binary)
___________________
1110 (in Binary) = 14 (in Decimal)
3. Bitwise XOR (^) Operator :-
when both operators are "1 - 1" or "0 - 0", it return "0" in the Output. If both operators are not same then the output will be "1".
A ^ B Output
1 1 0
1 0 1
0 1 1
0 0 0
For Example -
let A = 10 (in Decimal) = 1010 (in Binary)
B = 14 (in Decimal) = 1110 (in Binary)
___________________
0100 (in Binary) = 4 (in Decimal)
4. Bitwise Complement (~) Operator :-
it is a unary operator (works only on single operand). it converts "1" into "0" where "0" into 1.
A ~A
1 0
0 1
5. Bitwise Right Shift (>>) Operator :-
This Operator Shifts all the bits towards right hand side by the specified number of positions in bits. (eg. >>1means 1 bits, >>2 means 2 bits, >>3 means 3 bits and so on towards right hand side.)
On shifting specified bits right hand side, Left bits will be vacant. These Vacant place will be filled by "0" automatically.
6. Bitwise Left Shift (<<) Operator :-
This Operator Shifts all the bits towards left hand side by the specified number of positions in bits. (eg. >>1means 1 bits, >>2 means 2 bits, >>3 means 3 bits and so on toward left hand side.)
On shifting specified bits left hand side, right bits will be vacant. These Vacant place will be filled by "0" automatically.
__________________________________________________________
Must Read :-
What is Operator in Programming Language
What is Arithmetic Operator in Programming Language
What is Relational Operator in C, C++ programming languages
What is Logical Operators in C, C++ Programming Language (English Explanation)
What is Logical Operator in C, C++ Language (Hindi Explanation)
No comments:
Post a Comment