Uploaded by Fazan Miah

Binary Shifting

advertisement
Binary Shifting
By the end of this worksheet you should:
•
•
•
know what a bit is
be able to define a byte
understand the impact of binary shifting
Binary shifting is just as its name suggests; we are shifting
or moving binary values left or right.
Each 1 or 0 is called a bit; which is short for Binary digIT.
BIT: The smallest unit of data in a computer.
It is either a 0 or a 1
Eight bits are called a byte.
We have been working in bytes since the first worksheet.
This is not unusual.
Computers have been working in bytes for a long time
and is currently the smallest size of memory any
computer can address; you cannot get a single bit out of
memory – they only come in blocks of 8!
BYTE: The smallest addressable unit of memory.
Made up of 8 bits.
So, a binary shift means moving each bit in the direction
defined by the amount defined. Since we work in bytes
any bits that go outside our block of 8 are lost forever.
Page 1 of 3
Binary Shifting
SHORT QUESTIONS:
1. What is a bit?
2. What is a byte?
3. How many bits are there in a byte?
4. What is the smallest amount of addressable
memory?
Let’s take an 8 bit (1 byte) binary value:
0 0 1 0 1 0 0 0
Now let’s shift this left by 2 bits:
0 0 1 0 1 0 0 0
ß 2 bits
1 0 1 0 0 0 0 0
Notice that the 1s have moved left two places,
Also notice that any empty bits are filled with 0s.
Now let’s shift the original byte by 3 places right:
0 0 1 0 1 0 0 0
3 bits à
0 0 0 0 0 1 0 1
Again, the ones have shifted three places, this time to the
right. Again, we have filled the empty bits with zeros.
Why?
Page 2 of 3
Binary Shifting
Why bother shifting?
Well, let’s look at what happens to the values
as we shift a value to the left:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
1
0
0
0
1
2
4
8
As we shift the binary value left its denary value doubles,
multiplies by 2.
Obviously if we shift to the right we divide by 2.
Let’s look at another value:
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
1
0
0
1
0
1
0
0
1
0
20
10
5
2
Notice that we are halving the number each time we shift
right (division by 2), but that once we start losing ones we
lose any fractional part.
So, half of 5 is 2.5, but we only get 2 because the 0.5 is
lost forever.
Computers are fast but they are not always accurate!
The impact of binary shifting is…
Each shift left is a multiple of 2.
So, two shifts to the left would be 2 x 2 or 4. This tells us
that two shifts to the left is the same as multiplying by
four (x4).
Three shifts to the left is 2 x 2 x 2 or 8; so, this is the same
as multiplying by 8.
Nothing to practice, just learn and remember; easy
really.
Page 3 of 3
Download