Binary Number System Explained

Document Details

AuthoritativeParadox3662

Uploaded by AuthoritativeParadox3662

Modern Academy

Tags

binary number system data representation computer science

Summary

This document provides a detailed explanation of binary, denary, and hexadecimal number systems. It outlines the fundamental concepts, characteristics, and conversions between these systems. Numerous examples are given throughout the text.

Full Transcript

1.1.1 Binary represents data As you progress through this book you will begin to realise how complex computer systems really are. By the time you reach Chapter 10 you should have a better understanding of the fundamentals behind computers themselves and the software that controls them. You will lear...

1.1.1 Binary represents data As you progress through this book you will begin to realise how complex computer systems really are. By the time you reach Chapter 10 you should have a better understanding of the fundamentals behind computers themselves and the software that controls them. You will learn that any form of data needs to be converted into a binary format so that it can be processed by the computer. However, no matter how complex the system, the basic building block in all computers is the binary number system. This system is chosen because it only consists of 1s and 0s. Since computers contain millions and millions of tiny 'switches', which must be in the ON or OFF position, they can be represented by the binary system. A switch in the ON position is represented by 1; a switch in the OFF position is represented by 0. 1 Data representation 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 2 18/02/21 3:22 PM 3 1.1 Number systems Switches used in a computer make use of logic gates (see Chapter 10) and are used to store and process data. 1.1.2 Binary, denary and hexadecimal systems The binary system We are all familiar with the denary number system which counts in multiples of 10. This gives us the well-known headings of units, 10s, 100s, 1000s, and so on: (104 ) 10 000 (103 ) 1000 (102) 100 (101 ) 10 (100 ) 1 2 5 1 7 7 Denary uses ten separate digits, 0-9, to represent all values. Denary is known as a base 10 number system. The binary number system is a base 2 number system. It is based on the number 2. Thus, only the two 'values' 0 and 1 can be used in this system to represent all values. Using the same method as denary, this gives the headings 20 , 21 , 22 , 23 , and so on. The typical headings for a binary number with eight digits would be: (27) 128 (26 ) 64 (25) 32 (24 ) 16 (23 ) 8 (22) 4 (21 ) 2 (20 ) 1 1 1 1 0 1 1 1 0 A typical binary number would be: 11101110. Converting from binary to denary The conversion from binary to denary is a relatively straightforward process. Each time a 1-value appears in a binary number column, the column value (heading) is added to a total. This is best shown by three examples which use 8-bit, 12-bit and 16-bit binary numbers: Example 1 Convert the binary number, 11101110, into a denary number. 128 64 32 16 8 4 2 1 1 1 1 0 1 1 1 0 The equivalent denary number is 128 + 64 + 32 + 8 + 4 + 2 = 238 Example 2 Convert the following binary number, 011110001011, into a denary number. 2048 1024 512 256 128 64 32 16 8 4 2 1 0 1 1 1 1 0 0 0 1 0 1 1 The equivalent denary number is 1024 + 512 + 256 + 128 + 8 + 2 + 1 = 1931 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 3 18/02/21 3:22 PM 4 1 Data representation Example 3 Convert the following binary number, 0011000111100110, into a denary number. 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 0 As with the two examples above, to convert this number to denary, each time a 1 appears in a column the column value is added to the total: 8192 + 4096 + 256 + 128 + 64 + 32 + 4 + 2 = 12 774 The same method can be used for a binary number of any size. Activity 1.1 Convert the following binary numbers into denary: a 0 0 1 1 0 0 1 1 b 0 1 1 1 1 1 1 1 c 1 0 0 1 1 0 0 1 d 0 1 1 1 0 1 0 0 e 1 1 1 1 1 1 1 1 f 0 0 0 0 1 1 1 1 g 1 0 0 0 1 1 1 1 h 1 0 1 1 0 0 1 1 i 0 1 1 1 0 0 0 0 j 1 1 1 0 1 1 1 0 k 0 0 0 1 1 1 1 0 0 1 1 1 l 0 1 0 1 0 1 0 1 0 1 0 0 m 1 1 1 1 0 0 0 0 1 1 1 1 n 0 1 1 1 1 1 0 0 1 0 0 0 o 0 1 1 1 1 1 1 1 1 1 1 1 p 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 q 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0 1 r 1 1 0 0 0 0 1 1 0 0 1 1 1 1 1 1 s 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 t 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Converting from denary to binary The conversion from denary numbers to binary numbers can be done in two different ways. The first method involves successive subtraction of powers of 2 (that is, 128, 64, 32, 16, and so on); whilst the second method involves successive division by 2 until the value "0" is reached. This is best shown by two examples: Example 1 Consider the conversion of the denary number, 142, into binary: Method 1 The denary number 142 is made up of 128 + 8 + 4 + 2 (that is, 142 -- 128 = 14; 14 -- 8 = 6; 6 -- 4 = 2; 2 -- 2 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 8-bit binary number: 128 64 32 16 8 4 2 1 1 0 0 0 1 1 1 0 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 4 18/02/21 3:22 PM 5 1.1 Number systems Method 2 This method involves successive division by 2. Start with the denary number, 142, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 142 (that is, 142 ÷ 2 = 71 remainder 0); then divide again by 2 (that is, 71 ÷ 2 = 35 remainder 1) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 142 read the remainders from bottom to top to get the binary number: 2 71 remainder: 0 1 0 0 0 1 1 1 0 2 35 remainder: 1 2 17 remainder: 1 2 8 remainder: 1 2 4 remainder: 0 2 2 remainder: 0 2 1 remainder: 0 0 remainder: 1 ▲ Figure 1.1 We end up with an 8-bit binary number which is the same as that found by Method 1. Example 2 Consider the conversion of the denary number, 59, into binary: Method 1 The denary number 59 is made up of 32 + 16 + 8 + 2 + 1 (that is, 59 -- 32 = 27; 27 -- 16 = 11; 11 -- 8 = 3; 3 -- 2 = 1; 1 -- 1 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 8-bit binary number: 128 64 32 16 8 4 2 1 0 0 1 1 1 0 1 1 Method 2 This method involves successive division by 2. Start with the denary number, 59, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 59 (that is, 59 ÷ 2 = 29 remainder 1); then divide again by 2 (that is, 29 ÷ 2 = 14 remainder 1) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 59 write the remainders from bottom to top to get the binary number: 1 1 1 0 1 1 2 29 remainder: 1 2 14 remainder: 1 2 7 remainder: 0 2 3 remainder: 1 2 1 remainder: 1 0 remainder: 1 ▲ Figure 1.1b 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 5 18/02/21 3:22 PM 6 1 Data representation If we want to show this as an 8-bit binary number (as shown in Method 1), we now simply add two 0's from the left-hand side to give the result: 0 0 1 1 1 0 1 1. The two results from both methods clearly agree. Both the above examples use 8-bit binary numbers. This third example shows how the method can still be used for any size of binary number; in this case a 16-bit binary number. Example 3 Consider the conversion of the denary number, 35 000, into a 16-bit binary number: Method 1 The denary number 35 000 is made up of 32768 + 2048 + 128 + 32 + 16 + 8 (that is, 35000 -- 32768 = 2232; 2232 -- 2048 = 184; 184 -- 128 = 56; 56 -- 32 = 24; 24 -- 16 = 8; 8 -- 8 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 16-bit binary number: 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 Method 2 This method involves successive division by 2. Start with the denary number, 35000, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 35000 (that is, 35000 ÷ 2 = 17500 remainder 0); then divide again by 2 (that is, 17500 ÷ 2 = 8750 remainder 0) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 35000 read the remainder from bottom to top to get the binary number: 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 2 17500 remainder: 0 2 8750 remainder: 0 2 4375 remainder: 0 2 2187 remainder: 1 2 1093 remainder: 1 2 546 remainder: 1 2 273 remainder: 0 2 136 remainder: 1 2 68 remainder 0 2 34 remainder 0 2 17 remainder 0 2 8 remainder 1 2 4 remainder 0 2 2 remainder 0 2 1 remainder 0 0 remainder 1 ▲ Figure 1.1c 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 6 25/02/21 11:12 AM 7 1.1 Number systems Activity 1.2 Convert the following denary numbers into binary (using both methods): a 4 1 b 6 7 c 8 6 d 1 0 0 e 1 1 1 f 1 2 7 g 1 4 4 h 1 8 9 i 2 0 0 j 2 5 5 k 3 3 0 0 0 l 8 8 8 m 4 0 9 5 n 1 6 4 0 0 o 6 2 3 0 7 The hexadecimal system The hexadecimal number system is very closely related to the binary system. Hexadecimal (sometimes referred to as simply 'hex') is a base 16 system and therefore needs to use 16 different 'digits' to represent each value. Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent each hexadecimal (hex) digit. A in hex = 10 in denary, B = 11, C = 12, D = 13, E = 14 and F = 15. Using the same method as for denary and binary, this gives the headings 160 , 161 , 162 , 163 , and so on. The typical headings for a hexadecimal number with five digits would be: (164 ) 65 536 (163 ) 4096 (162) 256 (161 ) 16 (160 ) 1 2 1 F 3 A A typical example of hex is 2 1 F 3 A. Since 16 = 24 this means that FOUR binary digits are equivalent to each hexadecimal digit. The following table summarises the link between binary, hexadecimal and denary: ▼ Table 1.1 Binary value Hexadecimal value Denary value 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 2 2 0 0 1 1 3 3 0 1 0 0 4 4 0 1 0 1 5 5 0 1 1 0 6 6 0 1 1 1 7 7 1 0 0 0 8 8 1 0 0 1 9 9 1 0 1 0 A 10 1 0 1 1 B 11 1 1 0 0 C 12 1 1 0 1 D 13 1 1 1 0 E 14 1 1 1 1 F 15 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 7 18/02/21 3:22 PM 8 1 Data representation Converting from binary to hexadecimal and from hexadecimal to binary Converting from binary to hexadecimal is a fairly easy process. Starting from the right and moving left, split the binary number into groups of 4 bits. If the last group has less than 4 bits, then simply fill in with 0s from the left. Take each group of 4 bits and convert it into the equivalent hexadecimal digit using Table 1.1. Look at the following two examples to see how this works. Example 1 1 0 1 1 1 1 1 0 0 0 0 1 First split this up into groups of 4 bits: 1 0 1 1 1 1 1 0 0 0 0 1 Then, using Table 1.1, find the equivalent hexadecimal digits: B E 1 Example 2 1 0 0 0 0 1 1 1 1 1 1 1 0 1 First split this up into groups of 4 bits: 1 0 0 0 0 1 1 1 1 1 1 1 0 1 The left group only contains 2 bits, so add in two 0s: 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 1 Now use Table 1.1 to find the equivalent hexadecimal digits: 2 1 F D 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 8 18/02/21 3:22 PM 9 1.1 Number systems Activity 1.3 Convert the following binary numbers into hexadecimal: a 1 1 0 0 0 0 1 1 b 1 1 1 1 0 1 1 1 c 1 0 0 1 1 1 1 1 1 1 d 1 0 0 1 1 1 0 1 1 1 0 e 0 0 0 1 1 1 1 0 0 0 0 1 f 1 0 0 0 1 0 0 1 1 1 1 0 g 0 0 1 0 0 1 1 1 1 1 1 1 0 h 0 1 1 1 0 1 0 0 1 1 1 0 0 i 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 j 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1 0 Converting from hexadecimal to binary is also very straightforward. Using the data in Table 1.1, simply take each hexadecimal digit and write down the 4-bit code which corresponds to the digit. Example 3 4 5 A Using Table 1.1, find the 4 bit code for each digit: 0 1 0 0 0 1 0 1 1 0 1 0 Put the groups together to form the binary number: 0 1 0 0 0 1 0 1 1 0 1 0 Example 4 B F 0 8 Again just use Table 1.1: 1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 Then put all the digits together: 1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 9 18/02/21 3:22 PM 10 1 Data representation Activity 1.4 Convert the following hexadecimal numbers into binary: a 6 C b 5 9 c A A d A 0 0 e 4 0 E f B A 6 g 9 C C h 4 0 A A i D A 4 7 j 1 A B 0 Converting from hexadecimal to denary and from denary to hexadecimal To convert hexadecimal numbers into denary involves the value headings of each hexadecimal digit; that is, 4096, 256, 16 and 1. Take each of the hexadecimal digits and multiply it by the heading values. Add all the resultant totals together to give the denary number. Remember that the hex digits A → F need to be first converted to the values 10 → 15 before carrying out the multiplication. This is best shown by two examples: Example 1 Convert the hexadecimal number, 4 5 A, into denary. First of all we have to multiply each hex digit by its heading value: 256 16 1 4 5 A (4 × 256 = 1024) (5 × 16 = 80) (10 × 1 = 10) (NOTE: A = 10) Then we have to add the three totals together (1024 + 80 + 10) to give the denary number: 1 1 1 4 Example 2 Convert the hexadecimal number, C 8 F, into denary. First of all we have to multiply each hex digit by its heading value: 256 16 1 C 8 F (12 × 256 = 3072) (8 × 16 = 128) (15 × 1 = 15) (NOTE: C = 12, F = 15) Then we have to add the three totals together (3072 + 128 + 15) to give the denary number: 3 2 1 5 318281\_C01\_CAM\_IGCSE CO\_SCI\_001\_044.indd 10 18/02/21 3:22 PM 11 1.1 Number systems Activity 1.5 Convert the following hexadecimal numbers into denary: a 6 B b 9 C c 4 A d F F e 1 F F f A 0 1 g B B 4 h C A 8 i 1 2 A E j A D 8 9 To convert from denary to hexadecimal involves successive division by 16 until the value "0" is reached. This is best shown by two examples: Example 1 Convert the denary number, 2004, into hexadecimal. This method involves successive division by 16 until the value 0 is reached. We start by dividing the number 2004 by 16. The result of the division including the remainder (even if it is 0) is written under 2004 and then further divisions by 16 are carried out (that is, 2004 ÷ 16 = 125 remainder 4; 125 ÷ 16 = 7 remainder 13; 7 ÷ 16 = 0 remainder 7). The hexadecimal number is obtained from the remainders written in reverse order: 16 2004 write the remainders from bottom to top to get the hexadecimal number: 7 D 4 (D=13) 16 125 remainder: 4 16 7 remainder: 13 0 remainder: 7 ▲ Figure 1.2a Example 2 Convert the denary number, 8463, into hexadecimal. We start by dividing the number 8463 by 16. The result of the division including the remainder (even if it is 0) is written under 8463 and then further divisions by 16 are carried out (that is, 8463 ÷ 16 = 528 remainder 15; 528 ÷ 16 = 33 remainder 0; 33 ÷ 16 = 2 remainder 1; 2 ÷ 16 = 0 remainder 2). The hexadecimal number is obtained from the remainders written in reverse order

Use Quizgecko on...
Browser
Browser