Converting Between Binary & Hexadecimal (OCR GCSE Computer Science): Revision Notes
Converting Between Binary & Hexadecimal
Binary and Hexadecimal
Binary (base 2) and hexadecimal (base 16) conversions are very useful for programmers because hexadecimal makes large binary numbers easier to manage. Each hexadecimal digit represents exactly four binary digits, also called a nibble, which makes converting between the two systems quick and straightforward.
Why Hexadecimal is Useful
- Compact: It's much shorter than binary. Instead of writing 8 bits (e.g., 11101011), you can just write two hex digits (EB).
- Easy to Convert: Since each hex digit corresponds to exactly 4 binary digits, conversion is quick and doesn't require complex calculations.
Converting Binary to Hexadecimal
Method
- Split the binary number into nibbles (groups of 4 bits).
- Convert each nibble to its hexadecimal equivalent.
Worked Example 1
Question: Convert 11101011 to hexadecimal.
Step 1: Split the binary number into two nibbles
- A nibble is a group of 4 bits, so we split the 8-bit binary number into two nibbles:1110 and 1011.
- This makes it easier to convert each nibble to hexadecimal.
Step 2: Convert the first nibble to hex
- The first nibble is 1110.
- 1110 in binary is equivalent to E in hexadecimal.
- This is because the binary value 1110 represents 14, and 14 is E in hex.
Step 3: Convert the second nibble to hex
- The second nibble is 1011.
- 1011 in binary is equivalent to B in hexadecimal.
- This is because the binary value 1011 represents 11, and 11 is B in hex.
Step 4: Combine the hex digits
- Now that we've converted both nibbles, we combine the hex digits E and B.
- Therefore, 11101011 in binary is EB in hexadecimal.
Final Answer: Hexadecimal equivalent
- The binary number 11101011 is equal to EB in hexadecimal.
Worked Example 2
Question: Convert 10011011 to hexadecimal.
Step 1: Split the binary number into two nibbles
- A nibble is a group of 4 bits, so we split the 8-bit binary number into two nibbles:1001 and 1011.
- This makes it easier to convert each nibble to hexadecimal.
Step 2: Convert the first nibble to hex
- The first nibble is 1001.
- 1001 in binary is equivalent to 9 in hexadecimal.
- This is because the binary value 1001 represents 9, which is the same in both denary and hexadecimal.
Step 3: Convert the second nibble to hex
- The second nibble is 1011.
- 1011 in binary is equivalent to B in hexadecimal.
- This is because the binary value 1011 represents 11, and 11 is B in hex.
Step 4: Combine the hex digits
- Now that we've converted both nibbles, we combine the hex digits 9 and B.
- Therefore, 10011011 in binary is 9B in hexadecimal.
Final Answer: Hexadecimal equivalent
- The binary number 10011011 is equal to 9B in hexadecimal.
Converting Hexadecimal to Binary
Method
- Replace each hex digit with its 4-bit binary equivalent.
Worked Example 1
Question: Convert hex 7D to binary.
Step 1: Convert the first hex digit to binary
- The first hex digit is 7.
- In hexadecimal, 7 is represented as 0111 in binary.
- This is because 7 in hex is the same as 7 in denary, and 7 in binary is 0111 (using 4 bits).
Step 2: Convert the second hex digit to binary
- The second hex digit is D.
- In hexadecimal, D is equivalent to 1101 in binary.
- This is because D in hex represents 13 in denary, and 13 in binary is 1101.
Step 3: Combine the two binary groups
- Now that we've converted both hex digits, we combine their binary equivalents:0111 (for 7) and 1101 (for D).
- Therefore, 7D in hex is 01111101 in binary.
Final Answer: Binary equivalent
- The hexadecimal number 7D is equal to 01111101 in binary.
Worked Example 2
Question: Convert hex A4 to binary.
Step 1: Convert the first hex digit to binary
- The first hex digit is A.
- In hexadecimal, A is represented as 1010 in binary.
- This is because A in hex represents 10 in denary, and 10 in binary is 1010 (using 4 bits).
Step 2: Convert the second hex digit to binary
- The second hex digit is 4.
- In hexadecimal, 4 is represented as 0100 in binary.
- This is because 4 in both hex and denary is the same, and 4 in binary is 0100.
Step 3: Combine the two binary groups
- Now that we've converted both hex digits, we combine their binary equivalents:1010 (for A) and 0100 (for 4).
- Therefore, A4 in hex is 10100100 in binary.
Final Answer: Binary equivalent
- The hexadecimal number A4 is equal to 10100100 in binary.
Key Points to Remember
- Hexadecimal uses 16 different digits: 0-9 and A-F (where A = 10, B = 11, up to F = 15).
- Binary uses 2 digits: 0 and 1.
- 1 hex digit = 4 binary digits.
- To convert binary to hex, group binary into 4-bit nibbles and convert each to a hex digit.
- To convert hex to binary, replace each hex digit with its 4-bit binary equivalent.