Bit Manipulation Flashcards

1
Q

What is the result of the expression (5 & 3)?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Bit manipulation is generally faster than arithmetic operations.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: The operation that shifts bits to the left is called _____.

A

left shift

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of using XOR (^) in bit manipulation?

A

To toggle bits or find differences.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the expression (a | b) do?

A

It performs a bitwise OR operation between a and b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: The expression (n & (n - 1)) == 0 checks if n is a power of two.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given n = 10, what is the binary representation?

A

1010

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the right shift operator (») do to a binary number?

A

It divides the number by 2 for each shift.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fill in the blank: The bitwise NOT operation is represented by the symbol _____.

A

~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the output of the expression (7 ^ 3)?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False: Left shifting a number by one bit is equivalent to multiplying it by 2.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How many bits are required to represent the number 15 in binary?

A

4 bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the effect of the expression (n & -n)?

A

It isolates the lowest set bit of n.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fill in the blank: The term ‘bit masking’ refers to _____.

A

using bitwise operations to set, clear, or toggle specific bits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the expression (n | (n - 1))?

A

It sets all bits to the right of the lowest set bit of n.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: Bit manipulation can be used for optimization in algorithms.

17
Q

What is the result of the expression (15 & 8)?

18
Q

Fill in the blank: The operation that shifts bits to the right is known as _____.

A

right shift

19
Q

What does the expression (n ^ n) yield?

20
Q

How do you check if a number is odd using bit manipulation?

A

Use (n & 1) == 1.

21
Q

True or False: The left shift operation can lead to overflow in some cases.

22
Q

What is the purpose of the operation (n & ~mask)?

A

To clear bits in n where mask has bits set to 1.

23
Q

Fill in the blank: The term ‘bit rotation’ refers to _____.

A

shifting bits and wrapping them around.

24
Q

What does the expression (n | 0) do?

A

It returns n unchanged.

25
Q

How can you toggle a specific bit at position k in a number n?

A

Use (n ^ (1 &laquo_space;k)).

26
Q

True or False: Bit manipulation can only be performed on integer types.