Skip to main content

Back to the full dot-point answer

SingaporeComputer ScienceQuick questions

Data Representation

Quick questions on Bitwise operations and masking explained: H2 Computing

7short Q&A pairs drawn directly from our worked dot-point answer. For full context and worked exam questions, read the parent dot-point page.

What are the four bitwise operators?
Show answer
Each operator combines two bits position by position (NOT takes one):
What are shifts?
Show answer
A left shift (<<) moves all bits left, filling with 0 on the right; shifting by kk multiplies an unsigned value by 2k2^k. A right shift (>>) moves all bits right; for an unsigned value it divides by 2k2^k, discarding the remainder.
What are masks?
Show answer
A mask is a chosen bit pattern used with an operator to act on specific positions. A single-bit mask for bit nn is 1 << n. The standard operations:
What is off-by-one bit numbering?
Show answer
Bit 0 is the least significant bit; 1 << 3 is bit 3, the fourth position. Confusing position with count is a frequent error.
What is q1?
Show answer
Give the Python expression to toggle bit 6 of an integer x. [1 mark]
What is q2?
Show answer
Compute 11001100211001100_2 AND 00111100200111100_2. [2 marks]
What is q3?
Show answer
What value results from left-shifting 00000101200000101_2 by 2, and what arithmetic operation is that? [2 marks]

Have a question we have not covered?

This dot-point answer is short enough that we have not extracted many short questions yet. Read the full dot-point answer or ask Mo, our study assistant, in the chat for follow ups.

All Computer ScienceQ&A pages