44 total
By the end of this topic, you should be able to:
Bit manipulation means changing, testing, or moving individual bits inside a binary number.
A bit is a single binary digit. It can only be 0 or 1.
In this topic, you need to understand two main uses of bit manipulation:
This is important because computers and embedded systems often store information as groups of bits. Each bit can represent something small, such as whether a switch is ON or OFF, whether a sensor has been triggered, or whether a warning light should appear.
A binary shift moves all bits in a binary value to the left or to the right.
There are three shift types in this syllabus:
You must also know the difference between left shift and right shift.
A logical shift moves bits left or right and fills any empty space with 0.
Logical shifts are mainly used for:
In a logical left shift, every bit moves one or more places to the left. New spaces on the right are filled with 0.
Look at this 8-bit value:
00001110
This is denary 14.
Now shift it left by 2 places:
The result is 00111000, which is denary 56.
A logical left shift by 1 usually multiplies the number by 2. A logical left shift by 2 usually multiplies the number by 4.
So here:
That matches the shifted result.
A left shift can be a quick way to multiply by powers of 2.
But this only works properly when no important bits are lost off the left side. If bits move out of the byte, the value may no longer be correct.
Sign in to view full notes