Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Understanding Bit Operator In C#
WhatsApp
Lawal Abdulateef
8y
4.9
k
0
1
25
Blog
bitOperationcodesnipet.rar
& (AND) Operator
Binary AND Operator copies a bit to the result, if it exists in both the operands also returns true, if and only if both the operands are true. Unary variant returns the address of its operand. Binary variant is the bitwise AND of two operands.
A
B
& (AND) Operator
0
0
0
0
0
0
1
0
0
1
0
0
1
1
1
1
1
1
0
0
0
0
1
0
| OR Operator
Binary OR Operator copies a bit, if it exists in either operand i.e. true, if one or both operand is
true, false; if both the operands are false .
A
B
| (OR) Operator
0
0
0
0
0
0
1
0
1
1
0
1
1
1
1
1
1
1
0
0
0
0
1
1
^
XOR
Returns true, if and only if, one of the operands is true.
A
B
^(XOR ) Operator
0
0
0
0
0
0
1
0
1
1
0
1
1
1
0
1
1
0
0
0
0
0
1
1
~ Complement operator
The ~ operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. Bitwise complement operators are given below.
A
~
0
1
0
1
1
0
1
0
1
0
1
0
0
1
0
1
<<
Binary Left Shift Operator
The number of bits specified by the right operand moves the left operands value left. The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. The type of the second operand must be an integer or a type that has a predefined implicit numeric conversion to int. Thus, for example, 37 << 3 is shifting the number 37 to the left by 3 places. Of course, we are working with the binary representation of 37. The binary form of 37 is 00100101. After sliding by 3 to the left, we are left with 00101. However, we need to add three 0's to complete the bit 00101000.
>>
Binary
Right Shift Operator
The number of bits specified by the right operand moves the left operands value right. The right-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. The type of the second operand must be an integer or a type that has a predefined implicit numeric conversion to the integer. For example, 37 >> 3 is shifting the number 37 to the right by 3 places. Of course, we are working with the binary representation of 37 The binary form of 37 is 00100101. After sliding by 3 to the left, we are left with 00100. However, we need to add three 0's to complete the bit 00000100. Hope, the tutorial was helpful. Happy coding.
Bit Operator in C#
C#
Up Next
Null Conditional Operator In C#
Ebook Download
View all
Regular Expressions (Regex) in C#
Read by 197 people
Download Now!
Learn
View all
Membership not found