21 Lecture
CS201
Midterm & Final Term Short Notes
Bit Manipulation
Bit manipulation is a technique used in programming to manipulate individual bits or groups of bits within a binary sequence. It involves using logical and arithmetic operations to perform tasks such as setting, clearing, or flipping individual
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- Which operator is used for bit-wise AND in C programming? A) & B) | C) ~ D) ^
Answer: A) &
- Which operator is used for bit-wise OR in C programming? A) & B) | C) ~ D) ^
Answer: B) |
- Which operator is used for bit-wise NOT in C programming? A) & B) | C) ~ D) ^
Answer: C) ~
- Which operator is used for bit-wise XOR in C programming? A) & B) | C) ~ D) ^
Answer: D) ^
- Which operator is used for shifting bits to the left in C programming? A) << B) >> C) & D) |
Answer: A) <<
- Which operator is used for shifting bits to the right in C programming? A) << B) >> C) & D) |
Answer: B) >>
- What is the result of 0101 AND 0011 in binary? A) 0100 B) 0011 C) 0001 D) 0110
Answer: C) 0001
- What is the result of 1010 OR 1100 in binary? A) 1000 B) 1110 C) 0010 D) 0100
Answer: B) 1110
- What is the result of 1010 XOR 1100 in binary? A) 1000 B) 0110 C) 0010 D) 0100
Answer: B) 0110
- What is the result of shifting 0011 to the left by one bit in binary? A) 0010 B) 0100 C) 1001 D) 0110
Answer: B) 0100
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is bit manipulation? Answer: Bit manipulation is a programming technique used to manipulate individual bits or groups of bits within a binary sequence using logical and arithmetic operations.
What are the benefits of using bit manipulation? Answer: Using bit manipulation can help to optimize code, reduce memory usage, and improve performance in certain cases.
What is the difference between bit-wise AND and bit-wise OR? Answer: Bit-wise AND returns 1 only if both bits being compared are 1, while bit-wise OR returns 1 if either bit being compared is 1.
What is bit-wise complement? Answer: Bit-wise complement is a unary operator that inverts all the bits of a given value.
What is the difference between left shift and right shift operations? Answer: Left shift moves the bits of a value to the left by a specified number of positions, while right shift moves the bits to the right.
What is a bitmask? Answer: A bitmask is a binary sequence used to perform bitwise operations on a set of values.
How can bit manipulation be used in encryption? Answer: Bit manipulation can be used to encrypt data by performing logical and arithmetic operations on the binary values of the data.
What are the risks associated with bit manipulation? Answer: Bit manipulation can be error-prone and difficult to debug, and it can also lead to security vulnerabilities if not implemented properly.
What is a flag variable? Answer: A flag variable is a binary value used to represent a particular condition or state, and it can be manipulated using bit-wise operations.
How can bit manipulation be used in optimizing code? Answer: Bit manipulation can be used to replace complex arithmetic operations with simpler bitwise operations, reducing the number of instructions and improving performance.