Bit Manipulation Flashcards
What is the result of the expression (5 & 3)?
1
True or False: Bit manipulation is generally faster than arithmetic operations.
True
Fill in the blank: The operation that shifts bits to the left is called _____.
left shift
What is the purpose of using XOR (^) in bit manipulation?
To toggle bits or find differences.
What does the expression (a | b) do?
It performs a bitwise OR operation between a and b.
True or False: The expression (n & (n - 1)) == 0 checks if n is a power of two.
True
Given n = 10, what is the binary representation?
1010
What does the right shift operator (») do to a binary number?
It divides the number by 2 for each shift.
Fill in the blank: The bitwise NOT operation is represented by the symbol _____.
~
What is the output of the expression (7 ^ 3)?
4
True or False: Left shifting a number by one bit is equivalent to multiplying it by 2.
True
How many bits are required to represent the number 15 in binary?
4 bits
What is the effect of the expression (n & -n)?
It isolates the lowest set bit of n.
Fill in the blank: The term ‘bit masking’ refers to _____.
using bitwise operations to set, clear, or toggle specific bits.
What is the purpose of the expression (n | (n - 1))?
It sets all bits to the right of the lowest set bit of n.
True or False: Bit manipulation can be used for optimization in algorithms.
True
What is the result of the expression (15 & 8)?
8
Fill in the blank: The operation that shifts bits to the right is known as _____.
right shift
What does the expression (n ^ n) yield?
0
How do you check if a number is odd using bit manipulation?
Use (n & 1) == 1.
True or False: The left shift operation can lead to overflow in some cases.
True
What is the purpose of the operation (n & ~mask)?
To clear bits in n where mask has bits set to 1.
Fill in the blank: The term ‘bit rotation’ refers to _____.
shifting bits and wrapping them around.
What does the expression (n | 0) do?
It returns n unchanged.
How can you toggle a specific bit at position k in a number n?
Use (n ^ (1 «_space;k)).
True or False: Bit manipulation can only be performed on integer types.
False