GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts
Performed on unsigned integers (normal binary numbers) Binary Shifts A binary shift is an operation done to all bits of a binary number in which they are moved a set number of places either left or right Logical Shift Performed on unsigned integers (normal binary numbers) Arithmetic Shift Performed on signed integers (negative binary numbers using two’s complement)
Binary Shifts In denary (decimal) when we want to multiply a number by 10 we move each number one place to the left and add a 0 to the end (and vice versa for division) To multiply by 10 we move digits to the left and add a 0 To divide by 10 we move digits to the right and remove a 0 3 1 2 8 A left shift of 1 is used for multiplying by 10 A right shift of 1 is used for dividing by 10
Logical shifts allow you to multiply and divide binary numbers Binary Shifts: Logical Logical shifts allow you to multiply and divide binary numbers Because binary is a base-2 number system, left and right shifts can be used for multiplying and dividing by powers of 2
Binary Shifts: Logical Direction Purpose Example 1 Left Multiply by 2 1010 (10) 10100 (20) = 2 Left Multiply by 4 1010 (10) 101000 (40) = 3 Left Multiply by 8 1010 (10) 1010000 (80) = 128 64 32 16 8 4 2 1
Binary Shifts: Logical Direction Purpose Example 1 Right Divide by 2 101000 (40) 101000 (20) = 2 Right Divide by 4 101000 (40) 101000 (10) = 3 Right Divide by 8 101000 (40) 101000 (5) = 128 64 32 16 8 4 2 1
Copy these examples into your workbook Binary Shifts: Logical Shift Direction Purpose Example 1 Left Multiply by 2 1010 (10) 10100 (20) = 2 Left Multiply by 4 1010 (10) 101000 (40) = 1 Right Divide by 2 101000 (40) 101000 (20) = 2 Right Divide by 4 101000 (40) 101000 (10) = Copy these examples into your workbook
Activity Shift Direction Purpose Example Result 1 Left Multiply by 2 0101 (5) 01010 (10) = 2 Left Multiply by 4 1111 (15) 111100 (60) = 1 Right Divide by 2 110010 (50) 110010 (25) = 2 Right Divide by 4 1010000 (80) 1010000 (20) = 128 64 32 16 8 4 2 1