Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitwise AND on 32-bit Integer

Tags:

c#

bitwise-and

How do you perform a bitwise AND operation on two 32-bit integers in C#?

Related:

Most common C# bitwise operations.

like image 346
Tony The Lion Avatar asked Dec 18 '09 16:12

Tony The Lion


People also ask

What does bitwise and do to integers?

The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.

What is bitwise Anding?

A bitwise OR is a binary operation that takes two bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits. The result in each position is 0 if both bits are 0, while otherwise the result is 1. For example: 0101 (decimal 5) OR 0011 (decimal 3) = 0111 (decimal 7)

What is a bitwise XOR?

XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).

What does bitwise and return?

The bitwise AND operator ( & ) returns a 1 in each bit position for which the corresponding bits of both operands are 1 s.


2 Answers

With the & operator

like image 153
David M Avatar answered Sep 29 '22 17:09

David M


Use the & operator.

Binary & operators are predefined for the integral types[.] For integral types, & computes the bitwise AND of its operands.

From MSDN.

like image 22
jason Avatar answered Sep 29 '22 18:09

jason