Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to Digital Electronics, Module 1: Intro to Digital Concepts Module 2 – Number Systems, Operations and Codes Introduction: A digital systems designer must be familiar with arithmetic number manipulation of decimal, binary, and hexadecimal (HEX) numbers. This module will show you how each of these number systems are related and will show you how to manipulate the data. You will learn how to convert between systems, how to do basic arithmetic in any number base, and how to perform addition and subtraction of signed, unsigned and floating point binary numbers. You will learn how to handle negative numbers and how to perform 2’s complement subtraction of binary numbers. Finally you will learn about codes, and how data is formatted and sent from one digital circuit to the next. CONCEPT 2-1: NUMBER SYSTEMS The difference between number systems is the base or number where a carry takes place. In decimal, the base is ten, and each digit at each position in the number can have a value of 0 through 9. At the number 10, a carry is generated. The weight of each position is equal to the base raised to the power of the position. The first position to the left of the decimal point is the 0th position, the next is position 1, the next is position 2, position 3, and so on. The weight of the 0 position is 10 to the 0th power (100=1). Any number raised to the power of zero is equal to 1, so the weight of the first digit is one. The weight of the next digit is 10 to the power of 1 (101=10), the next is 10 to the positional power of 2 (102=100), and so on. Consider the number 1987. Seven is in the zero position, eight is in the 1 position, nine is in the 2 position and one is in the 3 position. Each digit is multiplied by its positional weight of 1000, 100, 10, 1. The decimal number 1987 is equivalent to 1000 + 900 + 80 + 7. Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 2 The same process works for all number systems. The positions are the same, but the weight for each position is the base raised to power of the position. In binary, the number count is 0, 1 with a carry generated at two; the base is equal to 2. Two raised to the power of zero is still one. Two to the power of 1 is 2. Two to the power of 2 is 4. Two raised to the power of 3 is 8. In binary, the weight of each digit position is twice the value of the previous position, or it doubles as 1, 2, 4, 8, 16, 32, 64, 128, and so on. We can use the same method to evaluate a binary number as we did to evaluate a decimal number. There can only be a 0 or a 1 value for each digit. Evaluate the number: 0 1 1 1 1 1 0 0 0 0 1 1. There are 12 digits. Starting with the right most digit, it is worth 1. The next is 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, and 2048. We add up the values at those positions where the digit is equal to 1, omitting those places where the digit is 0 (0 times anything = 0). The above binary number has a decimal value of: 1024 + 512 + 256 + 128 + 64 + 2 + 1 = 1987 Definition 2.1: Base The base of a number system is the numeric value that is reached when a carry takes place. In a decimal system this is ten, in a binary system it is two, in a hexadecimal system it is 16. All number systems have single symbols, which have a counting number value up to the base minus one. In decimal the numbers go from 0 through 9 with a carry at 10, in binary, the numbers are 0 or 1 with a carry at 2, and in hexadecimal, the numbers run from 0 through 9 corresponding to 0 thru 9 in decimal, then A thru F (where F is worth 15 in decimal). The carry takes place at a count of 16. Definition 2.2: Digit Position Number systems must record values much greater than the value of the base, so several digits or numbers, side by side in succession, are needed to express a value. Each digit in the number system is weighted according to its position. The position is the location of the digit relative to the decimal point. The decimal point is the location immediately to the right of the first whole value in the number. The Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 3 first number is in position 0, the next is in position 1, the next is in position 2, and so on. Definition 2.3: Positional Weight The weight of a digit is the value assigned to its position in the number. The weight is calculated as the base of the number system raised to the positional power. The first, or 0th position is worth 1 in all number systems; the next, or 1 position, is worth the value base in all number systems. In decimal this is 10, in binary this is 2, and in hexadecimal this is 16. The value of any digit in a number is equal to its counting value times its positional weight CONCEPT 2-2: Conversion from Binary to Hexadecimal Each hexadecimal digit can represent, or be represented by four binary bits. To convert from binary to HEX, divide the binary number into four bit slices, and substitute the equivalent hexadecimal digit. Four binary bits result in sixteen combinations of ones and zeros. Each combination has a decimal and a hexadecimal value. Conversion between binary and hexadecimal requires substitution from the table below: Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 4 CONCEPT 2.3: Conversion from Hexadecimal to Binary Conversion from HEX to binary is the opposite process. Substitute the four binary bit equivalent for each HEX digit. Convert the four hexadecimal numbers into their equivalent 16 binary number. 7 C 3H = 0 1 1 1 1 1 0 0 0 0 1 1 B. Note the "H" and "B" at the end of each number tells us the numbers are hexadecimal (HEX), and binary numbers respectively. CONCEPT 2-4: Conversion from Hexadecimal to Decimal Hexadecimal is a base 16 number system. Each digit has a counting value from zero to 15. Each positional weight is equal to 16 to the power of the position. As an example, we will convert the number 7 C 3 H to its decimal equivalent. The 0 at the front is a convention to designate the E 3 9 value as a number and not a string of letters. The H on the end means it is a HEX number or base 16. The The The The 3 position is worth 3 x 160 = 3 x 1 C position is worth 12 x 161 = 12 x 16 7 position is worth 7 x 162 = 7 x 256 three values are added together CONCEPT 2-5: = 3 = 192 = 1792 = 1987 decimal Conversion from Decimal to Binary One method of converting from decimal to binary subtracts the binary positional weights from the decimal number being converted starting with the largest value that will subtract leaving 0 or a positive value. Example: Convert 1987 to binary. 1. Create a binary weighted progression: 2048 1024 512 256 128 64 32 16 8 4 2 1 Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 2. 5 Progressively subtract the binary position weights from the decimal number, putting a “1” by each positional weight that will subtract leaving a zero or a positive remainder: 1987 - 1024 963 2048 0 963 - 512 451 1024 1 512 1 451 - 256 195 256 195 - 128 67 128 1 67 - 64 3 64 1 32 1 3 - 2 1 16 0 8 0 1 -1 0 4 0 2 0 1 1 1 After 64 is subtracted from the previous remainder of 67, a remainder of 3 is left. Therefore 32, 16, 8, and 4 will not subtract, thus these positions get a zero. CONCEPT 2-6: Addition in any Number System When doing addition in any number system, a carry is generated if the value of the number system base is reached. The carry is added to the next higher digit. In binary, a carry is generated every time that 1+1 is added. The base of a number system is the number where a carry occurs. The manipulation of the numbers is the same for all number systems. In binary, if you add two bits, there are three possible results. 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 0 and a carry, or 1 0. The carry takes place when the value of two is reached, and therefore two is the base number. CONCEPT 2-7: Multiplication by the Number System Base Any number system can be multiplied by its base by moving the decimal point to the right one place, or by adding a zero to the least significant digit end of the number (right most position.) In decimal, 19 x 10 = 190. In binary, 1101 x 2 = 11010 Introduction to Digital Electronics, Module 1: Intro to Digital Concepts CONCEPT 2-8: 6 Division by the Number System Base Any number system can be divided by its base by moving the decimal point to the left one place. In decimal , 192/10 = 19.2. In binary, 11010/2 = 1101 . CONCEPT 2-9: Getting the 2’s Complement of a Binary Number The 2’s complement of a binary number allows a computer to perform addition and subtraction of signed numbers, and to get a result that keeps track of a negative or positive sign or result. To get the 2’s complement you must first find the 1’s complement. The 1's complement is found by inverting each binary digit: 1 1 0 1 0 -- 1's complement = 0 0 1 0 1. The 2's complement can be realized by adding a binary 1 to the 1's complement: 1 1 0 1 0 - 2's complement = 0 0 1 0 1 + 1 = 0 0 1 1 0. The same result can be achieved by taking the original number, 1 1 0 1 0, and starting from the least significant digit, move to the left of the first 1. Leave the first 1 you come to, and invert everything else to the left. Using our number 1 1 0 1 0, the 2's complement becomes 0 0 1 1 0, using the "invert everything left of the first 1" method. CONCEPT 2-10: 2’s Complement Subtraction Two binary numbers can be subtracted by taking the 2’s complement of the subtrahend (number being subtracted), and adding it to the minuend. If a carry bit is generated by the addition of the 2’s complemented subtrahend, and the uncomplemented minuend, the sign is positive, and the resulting sum is the correct answer. If no carry is generated, the result is a negative sign, and an inverted result. To get the correct negative value, the inverted result must be 2’s complemented. Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 7 CONCEPT 2-11: Signed Numbers Numbers that can either be positive or negative, such as voltage, can use the most significant bit as a sign bit. A "0" means the value is positive, and a "1" means the value is negative. This relates to the 2's complement system because negative numbers are the 2's complement of the corresponding positive value. Just remember that if the most significant bit is being used as a sign bit, it cannot also be part of the number magnitude. CONCEPT 2-12: Arithmetic Operations with Signed Numbers When performing arithmetic operations using signed numbers, the result will give you the sign of the result, but the magnitude of the answer is also dependant on a resulting carry, or 2's complement overflow. This is the carry bit in the previous example. Introduction to Digital Electronics, Module 1: Intro to Digital Concepts 8 CONCEPT 2-13: Floating Point Numbers A floating point number can have a decimal point or a fractional value. When a number in any number system has digits to the right of the decimal point, the positions have negative values starting with –1, then –2, -3, and so on. The weight of each position is the base raised to the negative power of the position. In binary, the number 1101.011 is equal to 13 from the left side + .25 + .125 for the digits on the right side of the decimal point. 1101.011 = 13.375 . CONCEPT 2-14: Binary Coded Decimal (BCD) In binary coded decimal, four binary bits are used to represent each decimal digit in a decimal number. Four bit binary combinations above 9 are not allowed. Many calculators use BCD systems to perform their mathematical operations directly. CONCEPT 2-15: Digital Codes and Parity Digital codes are often used to represent everything from the alphabet to strange instrument weightings or number sequences. The most common use of codes is in error detection and correction. A binary sequence of bits can tell you if data has been corrupted. Some codes look for a repeated pattern and send a key to verify that the pattern was not changed during transmission. Parity sends an additional 1 or 0 at the end of a sequence of binary bits. The 1 or 0 is sent to keep the number of 1's being transmitted either an odd or an even count. If the data received has an odd number of 1's, like 1, 3, 5, 7, 9, etc. ...., to maintain even parity, the parity bit would be 1. For all even numbers of 1 in the binary sequence, 2, 4, 6, 8, etc. ..., the parity bit would be 0. This allows for detection of a single bit error.