Skip to content

9618 · 4.3

Bit manipulation — common mistakes

Common exam mistakes on 9618 Bit manipulation. Learn what loses marks, then practise the topic with Examiner’s Ink.

Exam tip 1

Examiners frequently test the difference between Logical and Arithmetic shifts. Always check if the question specifies a signed (two's complement) or unsigned number. If signed, use ASR for right shifts. If unsigned, use LSR. If the question doesn't specify, state your assumption, but LSR is the default for 'logical shift'.

Why is bit manipulation considered faster than normal arithmetic?

Bitwise operations like shifting and logical AND/OR/XOR often map directly to single, extremely fast instructions on the CPU. A multiplication like x * 4 might involve several steps, whereas a bit shift x<<2x << 2 is a single CPU cycle on most architectures, making it significantly more efficient.

What is the point of an Arithmetic Shift Left if it's the same as a Logical Shift Left?

It's mainly for conceptual consistency and completeness in instruction set design. While the result is identical (vacant LSB is filled with 0), having an ASL instruction allows a programmer or compiler to signify that they are performing a multiplication on a signed number, even if the underlying mechanism is the same as for an unsigned one. For your exams, you must know they are functionally identical.

In an exam, how do I know which bit is bit 0?

By convention, bit 0 is the rightmost bit (the least significant bit, LSB). Bit 1 is the next one to the left, and so on. For an 8-bit byte, the bits are numbered 7, 6, 5, 4, 3, 2, 1, 0 from left to right. If an exam question deviates from this, it will be explicitly stated.

Can I use bit manipulation to divide by a non-power-of-2 number, like 3?

Not directly with a simple shift. Bit shifts only work for multiplication and division by powers of 2 (2, 4, 8, 16...). Dividing by other numbers requires more complex algorithms, though some can be optimised using a combination of shifts, additions, and subtractions.