NEXT PAGE >
NEGATIVE NUMBERS |
|
|
DATA REPRESENTATION - 1.1.5 | BINARY SHIFT
Topics from the Cambridge IGCSE (9-1) Computer Science 0984 syllabus 2023 - 2025.
OBJECTIVES
1.1.5 Perform a logical binary shift on a positive 8-bit binary integer and understand the effect this has on the positive binary integer
1.1.5 Perform a logical binary shift on a positive 8-bit binary integer and understand the effect this has on the positive binary integer
WHAT IS A BINARY SHIFT
Performing a logical binary shift on a positive 8-bit binary integer involves shifting all the bits in the binary number to the left or right by a specified number of positions. The shift can be either a left shift, which involves moving all the bits to the left and adding 0's on the right, or a right shift, which involves moving all the bits to the right and adding 0's on the left.
The effect of a logical binary shift on a positive binary integer depends on the direction and the number of bit positions being shifted. In a left shift, the value of the binary number is effectively multiplied by 2 to the power of the number of bit positions being shifted. This is because each bit in the binary number represents a power of 2, and shifting the bits to the left increases the value of the number by a factor of 2. Conversely, in a right shift, the value of the binary number is effectively divided by 2 to the power of the number of bit positions being shifted. This is because shifting the bits to the right decreases the value of the number by a factor of 2.
For example, let's consider the binary number 00011010. If we perform a left shift by 2 positions, we get 01101000. This is equivalent to multiplying the original value (26 in denary) by 2^2, which gives us 104 in denary. On the other hand, if we perform a right shift by 3 positions, we get 00000011. This is equivalent to dividing the original value (26 in denary) by 2^3, which gives us 3 in denary.
This operation is commonly used in digital systems and programming languages to perform efficient arithmetic and data manipulation operations on binary data.
The effect of a logical binary shift on a positive binary integer depends on the direction and the number of bit positions being shifted. In a left shift, the value of the binary number is effectively multiplied by 2 to the power of the number of bit positions being shifted. This is because each bit in the binary number represents a power of 2, and shifting the bits to the left increases the value of the number by a factor of 2. Conversely, in a right shift, the value of the binary number is effectively divided by 2 to the power of the number of bit positions being shifted. This is because shifting the bits to the right decreases the value of the number by a factor of 2.
For example, let's consider the binary number 00011010. If we perform a left shift by 2 positions, we get 01101000. This is equivalent to multiplying the original value (26 in denary) by 2^2, which gives us 104 in denary. On the other hand, if we perform a right shift by 3 positions, we get 00000011. This is equivalent to dividing the original value (26 in denary) by 2^3, which gives us 3 in denary.
This operation is commonly used in digital systems and programming languages to perform efficient arithmetic and data manipulation operations on binary data.
HOW TO PERFORM A BINARY SHIFT
Here are two example tables showing the the process of a binary shift and the outcome of each.
In this example, we have a binary number represented in an 8-bit format with the values of each bit position indicated in the column headers. The original binary number is 10110010 (178 in denary), which is represented in the first row of Table 1. We want to perform a left shift by 2 positions, which involves moving all the bits to the left and adding 0's on the right. The resulting binary number is 11001000 (200 in denary), which is represented in the first row of Table 2.
In this example, we have the same binary number represented in Table 3, which is 10110010 (178 in denary). We want to perform a right shift by 3 positions, which involves moving all the bits to the right and adding 0's on the left. The resulting binary number is 00001011 (11 in denary), which is represented in the first row of Table 4.
CHECK YOUR KNOWLEDGE
What is the result of performing a left shift by one place on the binary number 0011?
A) 00110
B) 0110
C) 1100
D) 1110
EXPLAINATION
The correct answer is C) 1100.
When you perform a left shift on the binary number 0011 by one place, it becomes 1100. This left shift effectively multiplies the original value by 2, which is a key characteristic of left shifts in binary.
When you perform a left shift on the binary number 0011 by one place, it becomes 1100. This left shift effectively multiplies the original value by 2, which is a key characteristic of left shifts in binary.
.
Binary | A base-2 number system used in computing that includes only two digits: 0 and 1.
Bit | The smallest unit of data in computing, represented as either 0 or 1.
Binary Shift | A method of moving the positions of binary digits either to the left or right, affecting the value of the binary number.
Left Shift | A binary shift where each digit is moved one or more places to the left, effectively multiplying the binary number by 2 for each place shifted.
Right Shift | A binary shift where each digit is moved one or more places to the right, effectively dividing the binary number by 2 for each place shifted.
Place Value | The value of a position in a binary number, each representing a power of 2, increasing from right to left.
Multiplication by Powers of 2 | The effect of a left shift, where the value of a binary number doubles with each left shift position.
Division by Powers of 2 | The effect of a right shift, where the value of a binary number halves with each right shift position.
Padding | The process of adding zeros to the right (in a left shift) or to the left (in a right shift) to maintain the binary structure after shifting.
Overflow in Shifting | Occurs when a left shift pushes bits beyond the register’s capacity, causing data to be lost.
Logical Shift | A type of binary shift that simply moves all bits left or right and inserts a 0 at the vacant positions, with no consideration for the sign of the number.
Arithmetic Shift | A binary shift typically used with signed numbers; it shifts the bits while maintaining the sign bit (the leftmost bit) in a right shift.
Bit | The smallest unit of data in computing, represented as either 0 or 1.
Binary Shift | A method of moving the positions of binary digits either to the left or right, affecting the value of the binary number.
Left Shift | A binary shift where each digit is moved one or more places to the left, effectively multiplying the binary number by 2 for each place shifted.
Right Shift | A binary shift where each digit is moved one or more places to the right, effectively dividing the binary number by 2 for each place shifted.
Place Value | The value of a position in a binary number, each representing a power of 2, increasing from right to left.
Multiplication by Powers of 2 | The effect of a left shift, where the value of a binary number doubles with each left shift position.
Division by Powers of 2 | The effect of a right shift, where the value of a binary number halves with each right shift position.
Padding | The process of adding zeros to the right (in a left shift) or to the left (in a right shift) to maintain the binary structure after shifting.
Overflow in Shifting | Occurs when a left shift pushes bits beyond the register’s capacity, causing data to be lost.
Logical Shift | A type of binary shift that simply moves all bits left or right and inserts a 0 at the vacant positions, with no consideration for the sign of the number.
Arithmetic Shift | A binary shift typically used with signed numbers; it shifts the bits while maintaining the sign bit (the leftmost bit) in a right shift.
1: What is a logical binary shift?
A) A type of sorting algorithm
B) A way of converting binary to denary
C) A method of manipulating binary numbers by shifting the bits left or right
D) A way of compressing digital images
2: What happens to a binary number when it is shifted left by one position?
A) The value is multiplied by 2
B) The value is divided by 2
C) The value is shifted right by one position
D) The value remains the same
3: What happens to a binary number when it is shifted right by one position?
A) The value is multiplied by 2
B) The value is divided by 2
C) The value is shifted left by one position
D) The value remains the same
4: Which of the following is a common use case for logical binary shifts in computer programming?
A) Sorting data in a database
B) Encrypting sensitive data
C) Manipulating binary data efficiently
D) Generating random numbers
5: What is the effect of a logical binary shift on the size of a binary number?
A) It always increases the size of the binary number
B) It always decreases the size of the binary number
C) It can increase or decrease the size of the binary number, depending on the direction and number of positions being shifted
D) It has no effect on the size of the binary number
6: If the binary value 110110 is shifted left by two positions, what is the resulting binary value?
A) 000011
B) 101101
C) 011011
D) 011000
7: If the binary value 10010010 is shifted right by three positions, what is the resulting binary value?
A) 00010010
B) 00010001
C) 10000100
D) 01001000
A) A type of sorting algorithm
B) A way of converting binary to denary
C) A method of manipulating binary numbers by shifting the bits left or right
D) A way of compressing digital images
2: What happens to a binary number when it is shifted left by one position?
A) The value is multiplied by 2
B) The value is divided by 2
C) The value is shifted right by one position
D) The value remains the same
3: What happens to a binary number when it is shifted right by one position?
A) The value is multiplied by 2
B) The value is divided by 2
C) The value is shifted left by one position
D) The value remains the same
4: Which of the following is a common use case for logical binary shifts in computer programming?
A) Sorting data in a database
B) Encrypting sensitive data
C) Manipulating binary data efficiently
D) Generating random numbers
5: What is the effect of a logical binary shift on the size of a binary number?
A) It always increases the size of the binary number
B) It always decreases the size of the binary number
C) It can increase or decrease the size of the binary number, depending on the direction and number of positions being shifted
D) It has no effect on the size of the binary number
6: If the binary value 110110 is shifted left by two positions, what is the resulting binary value?
A) 000011
B) 101101
C) 011011
D) 011000
7: If the binary value 10010010 is shifted right by three positions, what is the resulting binary value?
A) 00010010
B) 00010001
C) 10000100
D) 01001000