OCR GCSE Computer Science (J277) - Topic 1.2.1: Units, Binary, Hexadecimal, Conversions, Binary Shifts
What do you already know or what are your best guesses?
Example Answers:
By the end of this lesson, you should be able to:
We know computers use binaryA base-2 number system using only 0s and 1s. The fundamental language of computers. (0s and 1s) at their core. However, long strings of binary can be difficult for humans to read, write, and remember accurately. For example, the binary number 1101010110111100
is quite a mouthful!
HexadecimalA base-16 number system using digits 0-9 and A-F. Often used as a shorthand for binary because 1 hex digit = 4 bits. (often shortened to "hex") is a base-16 number system that provides a more human-friendly way to represent binary data. It's widely used in computing for this reason.
We'll also explore binary shiftsAn operation that moves all bits in a binary number to the left or right. Used for quick multiplication or division by powers of 2., which are simple operations on binary numbers that have powerful mathematical effects.
a) What is the base of the hexadecimal number system?
b) How many binary bits does one hexadecimal digit represent?
c) Complete the table for the 16 hexadecimal digits and their denary equivalents:
To convert a denary number to hexadecimal:
Hexadecimal Output:
To convert a 2-digit hexadecimal number (e.g., A5) to denary:
Denary Output:
To convert an 8-bit binary number to hexadecimal:
Hexadecimal Output:
To convert a 2-digit hexadecimal number to an 8-bit binary number:
8-bit Binary Output:
Experiment with hexadecimal color codes! Input two hex digits (00-FF) for Red, Green, and Blue to see the color. Then, try to match the target color.
Your Hex: #000000
Target Hex: (Hidden)
A binary shift left moves all bits in a binary number one or more places to the left. New empty positions on the right are filled with zeros. Each shift left multiplies the denary value by 2.
Original Denary:
Shifted Binary:
Shifted Denary:
A binary shift right moves all bits one or more places to the right. Bits shifted off the right end are lost. New empty positions on the left are usually filled with zeros (for unsigned numbers). Each shift right divides the denary value by 2 (integer division).
Original Denary:
Shifted Binary:
Shifted Denary:
1. Shift 00101100
left by 2 places.
2. Shift 11100000
right by 3 places.
3. What happens if you shift 10000001
left by 1 place (in an 8-bit register)?
Below are some binary shift operations with incorrect results or explanations. Identify the mistake and explain why it's wrong in the box provided.
Problem 1:
An 8-bit binary number 11001010
(denary 202) is shifted left by 1 place.
Provided "Solution":
11001010
(Denary: 202)10010100
Problem 2:
An 8-bit binary number 00001101
(denary 13) is shifted right by 1 place.
Provided "Solution":
00001101
(Denary: 13)00000110
For more extensive practice, download and complete the following Excel worksheets. They contain many more questions to help you master these conversions and shifts.
Note: You will need Microsoft Excel or a compatible spreadsheet program to open these files.
Where is Hexadecimal Used?
#FF0000
for red, #00FF00
for green. Each pair of hex digits represents the intensity of Red, Green, and Blue.00:1A:2B:3C:4D:5E
).Why are Binary Shifts Useful?
Myth 1: "Hexadecimal is a different way of storing numbers in a computer."
Reality: Computers fundamentally store and process everything in binaryA base-2 number system using only 0s and 1s. The fundamental language of computers.. Hexadecimal is simply a more human-readable representationHow data is shown or interpreted. Hexadecimal is a representation of binary data. of binary data. It's a shorthand, not a different storage method at the hardware level.
Myth 2: "Binary shifts always give the exact mathematical result for multiplication and division."
Reality: While a left shift accurately multiplies by powers of 2 (unless overflowAn error that occurs when the result of a calculation is too large to fit in the available number of bits. occurs), a right shift performs integer divisionDivision where any fractional part (remainder) is discarded. E.g., 7 / 2 = 3 in integer division.. This means any fractional part of the result is lost (e.g., 00000111
(7) shifted right by 1 becomes 00000011
(3), not 3.5). Also, overflow can happen with left shifts if the result is too large for the number of bits available.
1. Convert the denary number 173 into hexadecimal. Show your working. [2 marks]
Mark Scheme:
2. Convert the hexadecimal number B4 into an 8-bit binary number. [1 mark]
Mark Scheme:
3. An 8-bit binary number 00110101
is shifted two places to the left.
(i) State the binary number after the shift. [1 mark]
(ii) State the denary equivalent of the original number and the shifted number. [2 marks]
(iii) Describe the arithmetic effect of this shift. [1 mark]
Mark Scheme:
4. Convert the denary number 97 into an 8-bit binary number. Show your working or method. [2 marks]
Mark Scheme:
5. Convert the 8-bit binary number 11001010 into denary. Show your working. [2 marks]
Mark Scheme:
6. An 8-bit binary number 01011000
is shifted three places to the right.
(i) State the binary number after the shift. [1 mark]
(ii) Describe the arithmetic effect of this shift on the original number. [1 mark]
Mark Scheme:
7. Explain one reason why hexadecimal numbers are often used in computer science. [2 marks]
Mark Scheme:
(Max 2 marks)
Click the button below to calculate your total score for the interactive tasks.
You've now explored hexadecimal and binary shifts!
Next, we'll look at:
Programmers sometimes need to perform simple addition or subtraction directly in hexadecimal, especially when working with memory addresses.
Research Task: How do you add two hexadecimal numbers, for example, A5 + 1B
? What happens if a sum in one column exceeds 'F' (15)?
We've looked at logical shifts (filling with zeros). For signed binary numbers (representing positive and negative values, often using Two's Complement), an arithmetic shift right behaves differently to preserve the sign bit.
Research Task: How does an arithmetic shift right differ from a logical shift right, particularly for negative numbers in Two's Complement form? Why is this distinction important?