Introduction to Digital System Design Z. Navabi Topic 1 Number Systems Zain Navabi Slides prepared by Katayoon Basharkhah Outline 2-1 Why Binary? 2-2 Decimal and Binary 2-3 Hex and Octal 2-4 Coding System 2-5 Binary arithmetic Introduction to Digital System Design - Copyright Zainalabedin Navabi 2 Why Binary? • Computers don’t understand words or numbers the way humans do. • In the lowest level, computers work with 0 and 1. • Binary number is base 2. Introduction to Digital System Design - Copyright Zainalabedin Navabi 3 Decimal and Binary Decimal Numbers Decimal Point Binary Point 4𝟒 𝟏𝟎 2 3 𝟏𝟎 2 𝟑 2 𝟐 𝟏𝟎 2 25.13= 1 𝟏 𝟏𝟎 2 𝟎 𝟏𝟎 2 2 5 -1 0 𝟏𝟎−𝟏 . -2 2 𝟏𝟎−𝟐 1 3 2 -3 𝟏𝟎−𝟑 2 -4 2𝟏𝟎 −𝟒 2*101 +5*100 + 1*10-1+3*10-2 Integer Fraction Introduction to Digital System Design - Copyright Zainalabedin Navabi 4 Decimal and Binary Binary Numbers Binary Point 4 3 2 1 0 2 2 2 2 2 1 1 0 0 1 -1 . -2 -3 -4 2 2 2 2 0 0 1 0 (11001.1010)2 = 1*24 + 1*23 +0*22 + 0*21 +1*20 + 0*2-1+0*2-2+ 1*2-3+0*2-4 = (25.125)10 Integer Fraction Binary to decimal conversion Introduction to Digital System Design - Copyright Zainalabedin Navabi 5 Decimal and Binary Decimal to Binary Conversion (Integer Part) (29.61)10=(?)2 Multiple divisions and collecting the remainders, the first remainder is the nearest digit to the binary point. 2 14 29 28 1 2 07 14 14 2 0 03 07 06 1 2 1 03 02 1 (29)D = (11101.)B Binary point Introduction to Digital System Design - Copyright Zainalabedin Navabi 6 Decimal and Binary Decimal to Binary Conversion (Fractional Part) Use multiplication to find the fractional part. 0.61*2 = 1 . 22 0.22*2 = 0 . 44 0.44*2 = 0 . 88 (0.61)10=(.100111)2 (29.61)10=(11101.100111)2 0.88*2 = 1 . 96 0.96*2 = 1 . 92 0.92*2 = 1 . 84 Introduction to Digital System Design - Copyright Zainalabedin Navabi 7 Octal and Hex To do conversions from base 2 to base 8(16), each 3(4) bits in base 2 must be converted into it’s equivalent in base 8(16). (35.37)10 = (00 100 011.010 111 00)2 (35.37)10 = (43.27)octal (35.37)10 = (0010 0011.0101 1100)2 (35.37)10 = (23.5C)Hex Introduction to Digital System Design - Copyright Zainalabedin Navabi 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F 8 Coding System 1- Signed Numbers • We define the left-most digit as the number’s sign digit. • The definition constructs the Sign and Magnitude representation of numbers. • In this representation all digits except the left-most construct the magnitude of the number, while the left-most digit being 1 shows that the number is negative or positive otherwise. Sign Magnitude 0 1001001 +73 1 1001001 -73 Introduction to Digital System Design - Copyright Zainalabedin Navabi 9 Coding System 2- Binary Coded Decimal • A system of writing numerals. • Assigns a four-digit binary code to each digit 0 through 9 in a decimal (base-10) numeral. 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 Introduction to Digital System Design - Copyright Zainalabedin Navabi 10 Coding System 3- Seven Segment Display Code • A system for simple display of digits 0 to 9. • Assigns a seven-digit binary code to each digit 0 through 9 (base-10) numeral. a b c d e f g 0 0000 1 1 1 1 1 1 0 1 0001 0 1 1 0 0 0 0 2 0010 1 1 0 1 1 0 1 3 0011 1 1 1 1 0 0 1 4 0100 0 1 1 0 0 1 1 5 0101 1 0 1 1 0 1 1 6 0110 1 0 1 1 1 1 1 7 0111 1 1 1 0 0 0 0 8 1000 1 1 1 1 1 1 1 9 1001 1 1 1 1 0 1 1 Introduction to Digital System Design - Copyright Zainalabedin Navabi 11 Coding System 3- Seven Segment Display Code Introduction to Digital System Design - Copyright Zainalabedin Navabi 12 Coding System Decimal Binary 4- Gray Code • Physical switches are not ideal: it is very unlikely that physical switches will change states exactly in synchrony. 0111 1111 1101 1001 0100 • Solution: Two successive values differ in only one bit. Introduction to Digital System Design - Copyright Zainalabedin Navabi Gray 0 0000 0000 1 0001 0001 2 0010 0011 3 0011 0010 4 0100 0110 5 0101 0111 6 0110 0101 7 0111 0100 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000 13 Coding System 5- ASCII • In some application storing text is the most important of all. The ASCII code is used for this mean. • Digits 0 through 9, lowercase and uppercase letters all have specific codes in this system. • Today, an extended ASCII table is also used alongside the basic one which contains the codes of foreigner letters. Introduction to Digital System Design - Copyright Zainalabedin Navabi 14 Coding System 5- ASCII • 8-bit codes are used to represent the ASCII codes, where the leftmost digit specifies which table a specific code belongs to. Codes starting with 1 are from the extended ASCII table and those starting with 0 belongs to the basic one. • Special characters are also included in the ASCII code range. It’s also true about the control characters. Introduction to Digital System Design - Copyright Zainalabedin Navabi 15 Binary arithmetic 1- Addition • Adding numbers in base 2 can be considered the same as decimal Addition. • The main problems can occur when doing subtractions. But even in this case the borrowing is just as it is in decimal numbers. +2 +2 +2 +2 +1 +1 +1 101101 + 011001 1000110 Addition 1 01101 +1 +1 +1 +1 - 0 01110 0 11111 Subtraction Introduction to Digital System Design - Copyright Zainalabedin Navabi 16 Binary arithmetic 2- Subtraction • With another look at the arithmetic in our decimal number system: The Largest number with the same number of digits plus 1 as our operand is added and subtracted 52 - 37 = 52 - 37 + 100 - 100 = 52 - (37 + 99) + 1 - 100 = 52 + (62 + 1) - 100 = 52 + 63 - 100 = 115 - 100 = 15 Negative of 37 • We have actually found a new way to negate 37 and that is the result of subtracting it from 99 and adding 1 to it. Introduction to Digital System Design - Copyright Zainalabedin Navabi 17 Binary arithmetic 2- Subtraction • With another look at the arithmetic in our decimal number system: 00110100 - 00100101 = 00110100 - 00100101 + 100000000 - 100000000 = 00110100 - 00100101 + 11111111 + 1 - 100000000 = 00110100 + 11011011 - 100000000 = 100001111 - 100000000 = 00001111 The negative of 00100101 • This representation for negative numbers is used in the 2’s Complement System. Introduction to Digital System Design - Copyright Zainalabedin Navabi 18 Binary arithmetic 3- Two’s complement • 2’s complementing a number is consisted of complementing it and then adding 1. • The same rule as the sign and magnitude representation for distinguishing positive numbers from negative ones applies in the 2’s complement system. • In the 2’s complement system, the positive numbers have the same form as they have in the sign and magnitude system. • 2’s complementing a negative number is performed as starting from the right-most digit until the first ‘1’ is reached and then complementing the rest of the digits. Introduction to Digital System Design - Copyright Zainalabedin Navabi 19 Binary arithmetic 4- Two’s complement arithmetic +1+1+1 +1 +1 00011011 + 01001101 01101000 Addition +1 +1 +1 +1 0 0 0 1 1 0 1 1 negating 0 0 0 1 1 0 1 1 - 01001101 + 10110011 -(00110010) 11001110 Binary Subtraction Introduction to Digital System Design - Copyright Zainalabedin Navabi 20 Binary arithmetic 5- Overflow 0 0 1 1 0 1 0 0 + 0 1 1 0 1 0 0 0 1 0 0 1 1 1 0 0 • A negative result has occurred from the addition of 2 positive numbers. • The result could have been shown correctly in 9 bits, but our system has at most 8. Introduction to Digital System Design - Copyright Zainalabedin Navabi 21 Binary arithmetic 5- Overflow Introduction to Digital System Design - Copyright Zainalabedin Navabi 22 Binary arithmetic 5- Overflow • A way for pointing out an overflow occurrence is when the sign bit of the result differs from that of the operands (if the operand’s sign bits are the same). • Solution: Sign-Extension Process + 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 Sign-Extension Introduction to Digital System Design - Copyright Zainalabedin Navabi 23 Conclusion We have covered: • • • • • Binary number representation. Binary to decimal conversion and vs. Coding systems like BCD, Gray code and ASCII. Binary arithmetic. Two’s complement system. Introduction to Digital System Design - Copyright Zainalabedin Navabi 24