9618 · 4.3
Bit manipulation — FAQ
Frequently asked questions for 9618 Bit manipulation. Direct answers first, then deeper explanation — then practise with marking.
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 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.