Converting Between Denary & Hexadecimal (OCR GCSE Computer Science): Revision Notes
Converting Between Denary & Hexadecimal
Converting Denary to Hexadecimal
Hexadecimal (or hex) uses base 16, meaning it has 16 digits: 0-9 and A-F (where A = 10, B = 11, up to F = 15).
Method 1: Division
- Divide the denary number by 16.
- The quotient (whole number result) is the leftmost hex digit.
- The remainder is the right hex digit.
Worked Example
Question**:** Convert 172 to hex
Step 1: Divide the denary number by 16
- When converting denary to hexadecimal, the first step is to divide the denary number by 16.
- In this case, we are converting 172 to hex.
- So, we divide 172 by 16: 172 ÷ 16 = 10 remainder 12.
Step 2: Interpret the quotient (whole number result)
- The quotient from the division represents the leftmost hex digit.
- Here, the quotient is 10.
- In hexadecimal, the number 10 is written as the letter A.
- So, the leftmost hex digit is A.
Step 3: Interpret the remainder
- The remainder of the division represents the rightmost hex digit.
- The remainder is 12.
- In hexadecimal, the number 12 is written as the letter C.
- So, the rightmost hex digit is C.
Final Answer: Combine the two hex digits
- Now that we have both hex digits (A and C), we combine them.
- Therefore, 172 in hex is written as AC.
Method 2: Binary to Hex
- Convert the denary number to an 8-bit binary number.
- Split the binary number into two 4-bit nibbles.
- Convert each nibble to its hex equivalent.
Worked Example
Question**:** Convert 172 to hex
Step 1: Convert the denary number to an 8-bit binary number
- First, we convert the denary number (172) into its binary form.
- In binary, 172 is written as 10101100.
- We use 8 bits because it's a standard format for representing numbers in binary (ensuring two hexadecimal digits).
Step 2: Split the binary number into two 4-bit nibbles
- Next, we split the 8-bit binary number into two groups of 4 bits, called "nibbles."
- The first 4 bits are 1010 and the second 4 bits are 1100.
Step 3: Convert each nibble to its hex equivalent
- Now, we convert each nibble (group of 4 bits) to its hexadecimal equivalent:
- 1010 in binary is A in hexadecimal.
- 1100 in binary is C in hexadecimal.
Final Answer: Combine the two hex digits
- Finally, we combine the two hex digits, A and C.
- Therefore, 172 in hex is written as AC.
Converting Hexadecimal to Denary
To convert from hex to denary, multiply each hex digit by its place value (16^position) and add the results together.
Method
- Multiply the left hex digit by 16.
- Multiply the right hex digit by 1.
- Add the two values together.
Worked Example
Question**:** Convert 3F to denary
Step 1: Multiply the left hex digit by 16
- The leftmost digit in a hexadecimal number represents the "16s place" because hex is base 16.
- In this example, the left hex digit is 3.
- Multiply 3 by 16 3 × 16 = 48.
- This gives us the value contributed by the left digit.
Step 2: Multiply the right hex digit by 1
- The rightmost digit represents the "1s place" in hexadecimal.
- In this example, the right hex digit is F, which is 15 in denary.
- Multiply 15 by 1 15 × 1 = 15.
- This gives us the value contributed by the right digit.
Step 3: Add the two values together
- Finally, add the two values from the previous steps: 48 + 15 = 63.
Final Answer: Denary equivalent
- Therefore, the hexadecimal number 3F is equal to 63 in denary.
Key Points to Remember
- Hexadecimal is a base-16 system using digits 0-9 and letters A-F (where A=10, B=11, ... F=15).
- To convert denary to hexadecimal, divide by 16 and use the quotient and remainder as hex digits.
- Alternatively, convert denary to binary, split the binary into 4-bit nibbles, and convert each to hex.
- To convert hexadecimal to denary, multiply the left digit by 16 and the right digit by 1, then add the results.