Binary, Hexadecimal and Two's Complement Representation
Original academy materialFree preview lesson. Enrol in ZIMSEC O-Level Computer Science (4021) to unlock every lesson, save your progress and earn your certificate. See the course
LEARNING OBJECTIVES
- Define the base of decimal, binary, and hexadecimal systems.
- Convert numbers between denary, binary, and hexadecimal formats.
- Calculate the value of binary digits using place values.
- Represent negative numbers using the two's complement method.
- Solve exam problems involving binary arithmetic.
IN SIMPLE TERMS
This lesson teaches you how computers speak. Computers use electricity to represent information as numbers. You will learn the three main ways computers count. These are denary, binary, and hexadecimal. This is the language of all hardware and software. By mastering these systems, you gain the skills needed to solve core exam questions.
Understanding these number systems is vital for your ZIMSEC exam. You will find these topics in Section A of the paper. These questions are predictable and easy to score if you follow the correct steps. You will learn the exact techniques that examiners look for to award full marks. We focus on accuracy and speed to help you pass.
Use this material by reading the definitions first. Then look at the examples provided below. Practice every calculation yourself with a pen and paper. Do not just read the steps. If you get stuck, look back at the place value diagram. Keep practicing until you can convert these numbers without any help.
KEY TERMS YOU MUST KNOW
- Denary: This is the base 10 number system. It uses the digits zero through nine which humans use daily.
- Binary: This is the base 2 number system. It only uses the digits zero and one.
- Hexadecimal: This is the base 16 number system. It uses numbers zero to nine and letters A to F.
- Base: This is the number of unique digits available in a counting system.
- Place value: This is the value assigned to a digit based on its position in a number string.
- Two's complement: This is a method used to represent negative numbers in binary format.
- Bit: This stands for binary digit. It is the smallest unit of data in a computer.
INTRODUCTION
The study of data representation is the bedrock of ZIMSEC O-Level Computer Science. Before a computer can process your name, a photo, or a game, it must translate that information into the only language it understands: binary. Understanding how numbers are represented using binary, hexadecimal, and two's complement is not just a theoretical exercise; it is the fundamental logic that enables all digital processing. In the examination, this topic frequently provides the foundation for Section A questions. Mastery here is high-yield because these are objective, marks-based questions where accuracy is rewarded, and mistakes are often avoidable. This lesson focuses on the mechanics of number systems and the specific techniques required to secure full marks in ZIMSEC examinations.
KEY CONCEPTS
Number systems are defined by their base. Decimal (Denary) is base 10, meaning it uses digits 0 through 9. Binary is base 2, using only 0 and 1. Hexadecimal is base 16, using digits 0 to 9 and letters A to F (where A=10, B=11, C=12, D=13, E=14, F=15).
The diagram above represents how any base system assigns a value to a digit based on its position. Starting from the right, the first position is the base to the power of 0, the next is the base to the power of 1, and so on. For binary, these values are 1, 2, 4, 8, 16, 32, 64, and 128. For hexadecimal, the values are 1, 16, 256, and so on. When converting from binary to denary, you multiply each bit by its corresponding place value and sum the results. To convert denary to binary, we use the method of successive division by 2 or by subtracting the largest possible power of 2.
Hexadecimal is used as a shorthand for binary because it is easier for humans to read and write. Since 16 is 2^4, exactly four binary bits can be represented by one hexadecimal digit. This is why you will often see 8-bit binary numbers split into two nibbles (4-bit chunks) for easier conversion.
Two's complement is the standard way computers represent negative integers. In an 8-bit system, the most significant bit (the leftmost bit) acts as a sign bit. However, instead of just being a sign, it represents a negative value. In 8 bits, the place values are -128, 64, 32, 16, 8, 4, 2, 1. To find the two's complement of a positive number, you invert all bits (change 0 to 1 and 1 to 0) and add 1 to the result.
WORKED EXAMPLE 1: CONVERTING DENARY TO BINARY
Question: Convert the denary number 73 into an 8-bit binary number. Step 1: Identify the powers of 2 that sum to 73. The largest power of 2 less than or equal to 73 is 64. Step 2: Subtract 64 from 73, which leaves 9. Step 3: The largest power of 2 less than or equal to 9 is 8. Step 4: Subtract 8 from 9, which leaves 1. Step 5: The remaining value is 1, which is 2^0. Step 6: Map these powers to their positions in an 8-bit byte. 64 is in the 7th position (2^6), 8 is in the 4th position (2^3), and 1 is in the 1st position (2^0). Step 7: Place a 1 in those positions and 0 elsewhere. Result: 01001001.
WORKED EXAMPLE 2: BINARY TO HEXADECIMAL
Question: Convert binary 11011110 to hexadecimal. Step 1: Split the binary string into two 4-bit nibbles: 1101 and 1110. Step 2: Convert the first nibble 1101. 8+4+0+1 = 13. In hex, 13 is D. Step 3: Convert the second nibble 1110. 8+4+2+0 = 14. In hex, 14 is E. Step 4: Combine the results. Result: DE.
WORKED EXAMPLE 3: TWO'S COMPLEMENT
Question: Represent -45 in 8-bit two's complement. Step 1: Find the 8-bit binary for +45. 32+8+4+1 = 00101101. Step 2: Invert the bits (One's Complement). 11010010. Step 3: Add 1 to the result. 11010010 + 00000001 = 11010011. Result: 11010011.
EXAMINER TRAPS
- Forgetting the leading zero: If an exam asks for an 8-bit number and your answer is only 7 bits, you will lose a mark. Always count your bits.
- Mixing up hexadecimal letters: Confusing A=10 and F=15 is a common careless error. Remember that A starts at 10.
- Sign bit confusion: Students often think the sign bit in two's complement is just 0 or 1, forgetting that in a byte, that first bit actually carries the weight of -128.
- Adding 1 incorrectly in two's complement: When adding 1, remember the carry rules. If you have 11111111 and add 1, it results in 00000000 (with an overflow), not something else.
- Base errors: Always double-check if the question asks for denary to binary or binary to hexadecimal. Reading the wrong direction is a frequent cause of zero marks on simple questions.
- Misinterpreting nibbles: When converting hex to binary, some students fail to provide four bits for each hex digit, leading to an incorrect length binary string. Even if the hex digit is 1 (0001), you must include the leading zeros.
PAST PAPER STYLE WALKTHROUGH
Question: Convert the denary number -26 into 8-bit two's complement format. State your steps.
Step 1: State the positive binary equivalent of 26. 26 is 16 + 8 + 2. In 8 bits, this is 00011010.
Step 2: Perform the one's complement (invert the bits). Invert 00011010 to get 11100101.
Step 3: Add 1 to the one's complement to reach two's complement. 11100101 + 00000001 = 11100110.
Final Answer: 11100110.
SUMMARY
Number systems are the language of computing. Binary (base 2) provides the electrical state, hexadecimal (base 16) provides the human-readable shorthand, and two's complement (signed binary) allows for the representation of negative values. Success in ZIMSEC exams in this area relies on rigorous checking of bit-lengths and careful adherence to the conversion algorithms. Practice these conversions daily until they become second nature, as they are essential building blocks for later topics like computer architecture and data transmission. By following the systematic steps outlined in this guide and being mindful of common examiner traps, you will be well-equipped to handle any question in this section of the syllabus. Remember: precision is the most important tool in your examination kit. Take your time, draw your tables, and verify your work.