answersLogoWhite

0

Why do you need to learn how to AND?

User Avatar

Anonymous

10y ago
Updated: 8/20/2019

The AND operator is a binary operator, thus it accepts two operands. However, the type of the operands depends upon whether you mean the logical AND or the bitwise AND.

The logical AND (&& in C/C++) accepts two boolean expressions, returning true if and only if both expressions evaluate true. If either or both evaluate false, the return is false.

int a=42, b=69;

assert (a==42 && b==69); // e.g., true AND true == true

The bitwise AND (& in C/C++) does the same thing but at the bitwise level, comparing each of the corresponding bits of each operand. If both bits are 1, then the output for that bit is 1, otherwise the output is 0. You do this to determine which specific bits appear in both operands. For this to work, both operands must be of the same type and length (in bits).

int a=42, b=69, c=a & b;

assert (c==0);

In binary:

a (00101010) &

b (01000101) =

c (00000000)

User Avatar

Wiki User

10y ago

What else can I help you with?