COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS COMBINATIONAL LOGIC Outcome 1 ?1 (a) Convert the following decimal numbers into 8-bit binary: (i) 10 (b) (iii) 00111110 (iv) 10010011 (ii) 2A (iii) 68 (iv) 0F (ii) 11011000 (iii) 01001110 (iv) 10010111 Convert the following decimal numbers into two-digit hexadecimal numbers: (i) 62 (f) (ii) 11100011 Convert the following 8-bit binary numbers to hexadecimal: (i) 00111011 (e) (iv) 182 Convert the following hexadecimal numbers to 8-bit binary: (i) F3 (d) (iii) 120 Convert the following 8-bit binary numbers to decimal: (i) 10101010 (c) (ii) 59 (ii) 5 (iii) 251 (iv) 129 Convert the following hexadecimal numbers into decimal: (i) BC (ii) F4 (iii) 56 (iv) AA ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2 ) 133 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?1 Solution (a) There a number of different ways in which decimal to binary conversion can be done. The quickest and simplest is to use an engineering calculator that lets you convert between bases. Even the windows-based calculator supports base conversion. Given below is an illustration of how this is done using the windows calculator. Only 6 binary digits appear as this is all that is required to represent 59 in binary, however to convert to an 8-bit representation just add two zeros, i.e. 00111011 Alternatively we can calculate the binary value of a decimal number using the binary weightings for 8 bits as shown below. Binary weighting expressed as power of 2 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 134 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS Finally we can calculate the result using the ‘divide by 2’ technique. Again using 59 as an example: (i) 10 converts to 00001010 MSB LSB (ii) 59 converts to 00111011 (see above) (iii) 120 converts to LSB MSB ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 135 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (iv) 182 converts to LSB MSB (b) (i) Binary weighting expressed as power of 2 (ii) Binary weighting expressed as power of 2 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 136 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (iii) Binary weighting expressed as power of 2 (iv) Binary weighting expressed as power of 2 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 137 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (c) Hexadecimal is number system based on 16 digits compared with decimal, which has 10, and binary, which has 2. The popularity of hexadecimal within the study and use of digital systems is that it provides a shorthand (efficient) method of representing binary patterns. Converting from hexadecimal to binary and binary to hexadecimal is also extremely easy. The table below shows the relationship between every hexadecimal digit and its 4-bit binary equivalent. Notice that the table is simply a binary count and all that really needs to be remembered are the binary patterns for A, B, C, D, E and F. B3 B2 B1 B0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 (i) Hexadecimal value 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal value 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 To convert the hexadecimal number F3 simply look at the table and extract the appropriate 4-bit binary pattern. F = 1111 3 = 0011 so the binary representation for F3 is 11110011. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 138 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (ii) For 2A: 2 = 0010 A = 1010 so the binary representation for 2A is 00101010. (iii) For 68 6 = 0110 8 = 1000 so the binary representation for 68 is 01101000. (iv) For 0F 0 = 0000 F = 1111 so the binary representation for 0F is 00001111. (d) The process of converting from binary to hexadecimal is simply a case of reversing the previous process. Divide the binary pattern into groups of four bits and read off the equivalent hexadecimal digit. In example (i) 00111011is broken into 0011 = 3 and 1011 = B. The hexadecimal representation of 00111011 is 3B. (ii) 11011000 = 1101 1000 = D8 (iii) 01001110 = 0100 1110 = 4E (iv) 10010111 = 1001 0111 = 97 Note: if the binary pattern does not divide into groups of four bi ts add 0s to the left-hand side, i.e. the MSB side until the pattern does divide. For example, 11001 only contains five binary digits (bits). If we add three 0s to the left-hand side we do not affect the value but we can now divide the pattern into groups of four bits: 00011001 = 19 in hexadecimal ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 139 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (e) There are three methods that we can use to convert decimal to hexadecimal. The simplest of all is to use an engineering calculator that has the facility to convert between bases. Again if we look at the calculator provide in Microsoft Windows we can see how this is done. The second method is to convert the decimal number into binary and then convert the binary number into hexadecimal. All of this has been demonstrated in the previous examples (a) – (d). The third method involves conversion using a table containing the weighted values of the hexadecimal digits. This is similar to the conversion between binary and decimal. Hexadecimal digit position Hexadecimal digit weighting ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 140 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (ii) Convert the decimal number 5 into hexadecimal. (iii) Convert decimal number 251 into hexadecimal. (iv) Convert the decimal number 129 to hexadecimal. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 141 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (f) (i) (ii) Convert the hexadecimal number BC to decimal. Convert the hexadecimal number F4 to decimal. (iii) Convert the hexadecimal number 56 to decimal. (iv) Convert the hexadecimal number AA to decimal. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 142 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 (a) Perform the following additions in 8-bit binary. Convert back to decimal to check your answer. (b) Perform the following subtractions in binary. Convert back to decimal to check your answer. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 143 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 Solution (a) The decimal numbers in this question have already been converted to binary in SAQ 1. The rules applied to binary addition are identical to those a pplied to decimal except that we must always remind ourselves that we are working in binary. (i) (ii) (iii) (iv) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 144 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (b) The decimal numbers in this question have already been converted to binary in SAQ 1. The rules applied to binary subtraction are identical to those applied to decimal except that we must always remind ourselves that we are working in binary. (i) 1–1=0 3–2=1 2 cannot be subtracted from 0 therefore a 1 is borrowed from the next column. This upper digit is now 2 2–1=1 (ii) (iii) (iv) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 145 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?3 (a) Represent the following numbers as 2s complement 8-bit binary numbers: (i) –10 (ii) 10 (v) 120 (vi) –120 (iii) 59 (iv) –59 (b) Explain why the decimal numbers 182 and –182 cannot be represented using 8-bit 2s complement representation. (c) Perform the following calculations using 8-bit 2s complement binary representation: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 146 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?3 Solution (a) 2s complement is a binary method of representing negative numbers. In 2s complement representation the MSB is used as a sign bit with 1 indicating a negative number and 0 representing a positive number. We will use (i) to illustrate the 2s complement system. (i) To represent –10 simply write down the binary value for 10: We then invert all the bits: Then we add 1 to this value: The answer is the 2s complement representation of –10: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 147 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS It is difficult to tell the value of this 8-bit 2s complement number simply by looking at it. To check the value of a negative number simply repeat the previous operations, i.e. invert all bits and add 1: (ii) Notice that there is no difference in representation, i.e. this looks like a standard 8-bit binary representation of 10. (iii) (iv) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 148 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (v) (vi) (b) If we use 8-bit 2s complement representation then the sign bit effectively reduces the size of the number to 7 bits. In 2s complement form the range of numbers that can be represented is: As can be seen, 182 and –182 fall outwith this range and so cannot be represented using 8-bit 2s complement. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 149 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (c) (i) (ii) (iii) (iv) If a carry is generated into the ninth bit simply ignore; the 8-bit answer will be correct ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 150 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS Outcome 2 ?1 (a) Identify the ANSI standard logic symbols shown and complete the truth tables in Fig SAQ 1 (i). Fig SAQ 1(i) (b) Draw the British Standard symbols for the logic gates shown Fig SAQ 1(i). (c) Write down the Boolean expression for each of the gates shown in Fig SAQ 1(i). ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 151 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?1 Solution (a) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 152 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (b) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 153 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 For the ANSI logic gates given in Fig SAQ 2: (a) write down the logic expression (b) write down the logic output for the inputs shown. Fig SAQ 2 ?3 For the BS logic gates given in Fig SAQ 3: (a) write down the logic expression (b) write down the logic output for the inputs shown. Fig SAQ 3 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 154 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 Solution (a), (b) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 155 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?3 Solution (a), (b) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 156 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS Outcome 3 ?1 (a) For the circuit shown in Fig SAQ 1(i) write down the Boolean expression for X. (b) Using the integrated circuit diagram sheet identify the Integrated Circuits used in this circuit and place appropriate pin numbers beside the gates. (c) Complete the truth table in Fig SAQ 1(ii). Fig SAQ 1(i) Fig SAQ 1(ii) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 157 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?1 Solution (a), (b) Fig SAQ 1(i) (c) Fig SAQ 1(ii) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 158 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 (a) For the circuit shown in Fig SAQ 2(i) write down the Boolean expression for X. (b) Using the integrated circuit diagram sheet identify the ICs used in this circuit and place appropriate pin numbers beside the gates. (c) Complete the truth table in Fig SAQ 1(ii). Fig SAQ 2(i) Fig SAQ 2(ii) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 159 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 Solution (a), (b) (c) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 160 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?3 For the following Boolean expressions: (i) (ii) (a) draw the logic circuit using ANSI symbols (your diagram should show the ICs selected and the appropriate pin connections) (b) hence, or otherwise, complete the truth tables given in Fig SAQ 3. Fig SAQ 3 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 161 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?3 Solution (i) Working from the output backwards: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 162 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS (ii) (b) ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 163 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?4 The truth table for a two-input logic circuit is shown in Fig SAQ 4. (a) From the truth table derive the Boolean expression that describes this table. (b) Using ANSI symbols draw the logic circuit that meets the requirements of this table. Your schematic should clearly show ICs used and pin numbers. Fig SAQ 4 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 164 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?4 Solution In this problem you are trying to generate a circuit from a truth table. To do this consider each input combination that provides a logic 1 output and work out how this could be achieved using an AND gate. These combinations are indicated by arrows in the diagram below. To illustrate consider the first combination, A = 0 and B = 0. In order to generate a logic 1 at the output an AND gate needs all its inputs to be logic 1 therefore we need to invert A and B: If we follow this argument for the second combination, A = 0 and B = 1, we need to invert A only to obtain a 1 from the AND gate output: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 165 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS The final step is to combine all the AND combinations into an OR gate. Recall that the OR gate will generate a logic 1 output when either of its inputs are logic, which is exactly what is needed for this circu it. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 166 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?5 The truth table for a three-input logic circuit is shown in Fig SAQ 5. (a) From the truth table derive the Boolean expression that describes this table. (b) Using ANSI symbols draw the logic circuit that meets the requirements of this table. Your schematic should clearly show ICs used and pin numbers. Fig SAQ 5 ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 167 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?5 Solution The only difference between this problem and SAQ 4 is the number of inputs. The way in which we solve the problem is identical. Identify the input combinations that give a logic 1 output and work out how a logic 1 could be achieved using an AND gate: The first combination is ABC = 001. As we have three inputs we will require a three-input AND gate. To obtain a logic 1 output for this combination we need to invert A and B: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 168 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS The second combination is ABC = 100. To obtain a logic 1 output for this combination we need to invert B and C: As before the final step is to combine all the AND combinations into an OR gate. Recall that the OR gate will generate a logic 1 output when either of its inputs are logic 1: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 169 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS Outcome 4 ?1 A simple logic control system for a central heating system has the following inputs: timer clock (C) 0 = outwith time period for central heating to be on 1 = within time period for central heating to be on room thermostat (T) 0 = room temperature above the set value 1 = room temperature below set value frost protection (F) 0 = room temperature above 4°C 1 = room temperature below 4°C When the output from the control system = 1 then the boiler will be ignited, allowing the system to produce heat. The frost protection will override the timer clock and the room thermostat should the temperature fall below 4°C. Design the logic control system to meet the above requirements. Your design should include the following: truth table Boolean logic expression logic diagram using ANSI symbols (this diagram must include IC identification and pin numbering). ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 170 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?1 Solution This outcome advances the combinational design processes one step further. In this outcome we are given a specification for a digital system and from that a practical circuit must be designed. The first step in this process is to generate a truth table. This problem has three inputs, C, T and F, therefore we need a three-input truth table. Each input condition must be carefully considered before placing a 1 or 0 in the output column. C T F OUT 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 1 1 1 1 1 Output will be 0 as frost setting is above 4° and timer outwith ON period. Output will be 1 as the frost setting is indicating that the temperature is below 4°. This overrides everything else. Output will be 0 as the frost setting is above 4° and tim er outwith ON period. Note it doesn’t matter that the temperature in the house is below the required value. Output will be 1 as the frost setting is indicating that the temperature is below 4°. This overrides everything else. Although we are within the ON period the temperature is above the frost setting and the set value so the central heating should be OFF and the output at 0. Output will be 1 as the frost setting is indicating that the temperature is below 4°. This overrides everything else. Output will be at 1 as we are in the ON period and the temperature is below the set value. Output will be 1 as the frost setting is indicating that the temperature is below 4°. This overrides everything else. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 171 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS The remaining steps are identical to those carried out in Outcome 3, i.e. generate an AND expression for each OUT = 1 condition and then OR all of these AND expression together: ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 172 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 173 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 174 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 The control logic for a simple alarm system in a house has three inputs and a single output, which activates an alarm. The three inputs are: windows sensor doors sensor master key. The sensors operate as follows: window sensor (W) 0 = all windows closed 1 = a window is open door sensor (D) 0 = all doors closed 1 = a door is opened master key (K) 0 = alarm system is disarmed 1 = alarm system is armed If the alarm system is disarmed then the logic signals from the sensors are ignored and the alarm will not sound. The alarm is activated by a logic 1 from the output of the control logic. Design the circuit to meet the requirements of this control logic. Your design should include the following: truth table Boolean logic expression logic diagram using ANSI symbols (this diagram must include IC identification and pin numbering). ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 175 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ?2 Solution As with the previous example a truth table must be generated and all input permutations carefully considered. The required ou tput and associated reasons are shown below. W D K OUT 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 Alarm is disarmed so it doesn’t matter what the other sensors are outputting, the output will be 0. System is armed but no doors or windows are open therefore the output is 0. Alarm is disarmed so it doesn’t matter what the other sensors are outputting, the output will be 0. System is armed and a door is open therefore the output is 1 in order to activate the alarm-driving circuitry. Alarm is disarmed so it doesn’t matter what the other sensors are outputting, the output will be 0. System is armed and a window is open therefore the output is 1 in order to activate the alarm-driving circuitry. Alarm is disarmed so it doesn’t matter what the other sensors are outputting, the output will be 0. System is armed and a door and a window are open therefore the output is 1 in order to activate the alarm-driving circuitry. Generate an AND expression for each OUT = 1 condition and then OR all of these AND expressions together to create the Boolean expression that fully describes the requirements of the truth table. ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 176 © Learning and Teaching Scotland 2004 COMBINATIONAL LOGIC: EXEMPLAR QUESTIONS AND SOLUTIONS ELECTRONIC AND ELECTRICAL FUNDAMENTALS (INT 2) 177 © Learning and Teaching Scotland 2004