Bird
0
0
DSA Cprogramming~5 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the AND (&) bitwise operator do between two bits?
The AND operator returns 1 only if both bits are 1; otherwise, it returns 0.<br>Example: 1 & 1 = 1, 1 & 0 = 0, 0 & 0 = 0.
Click to reveal answer
beginner
Explain the OR (|) bitwise operator with an example.
The OR operator returns 1 if at least one of the bits is 1; otherwise, it returns 0.<br>Example: 1 | 0 = 1, 0 | 0 = 0, 1 | 1 = 1.
Click to reveal answer
beginner
What is the result of XOR (^) between two bits?
XOR returns 1 if the bits are different, and 0 if they are the same.<br>Example: 1 ^ 0 = 1, 1 ^ 1 = 0, 0 ^ 0 = 0.
Click to reveal answer
beginner
What does the NOT (~) operator do to a bit?
The NOT operator flips the bit: 1 becomes 0, and 0 becomes 1.<br>Example: ~1 = 0, ~0 = 1 (in binary representation).
Click to reveal answer
beginner
What happens when you perform a left shift (<<) on a number?
Left shift moves all bits to the left by the given number of positions, adding zeros on the right.<br>This is like multiplying the number by 2 for each shift.<br>Example: 3 (011) << 1 = 6 (110).
Click to reveal answer
What is the result of 5 & 3 in binary? (5 = 0101, 3 = 0011)
A0100
B0111
C0001
D0010
Which operator flips all bits of a number?
AOR (|)
BNOT (~)
CAND (&)
DXOR (^)
What does the expression (6 >> 1) evaluate to? (6 = 0110 in binary)
A0001 (1)
B1100 (12)
C0110 (6)
D0011 (3)
What is the result of 4 ^ 4?
A0
B4
C8
D1
Which bitwise operator returns 1 if either bit is 1?
AOR (|)
BXOR (^)
CAND (&)
DNOT (~)
Describe how the AND, OR, XOR, and NOT bitwise operators work with simple examples.
Think about how each operator treats pairs of bits.
You got /4 concepts.
    Explain what happens when you perform left shift (<<) and right shift (>>) on a binary number.
    Imagine sliding bits left or right in a row.
    You got /4 concepts.