Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Logic Lecture 2 Number Systems

Similar presentations


Presentation on theme: "Digital Logic Lecture 2 Number Systems"— Presentation transcript:

1 Digital Logic Lecture 2 Number Systems
By Dr Zyad Dwekat The Hashemite University Computer Engineering Department

2 The Hashemite University
Outline Introduction. Basic definitions. Number systems types. Conversion between different number systems. Examples. The Hashemite University 2

3 The Hashemite University
Introduction There are 4 numbering systems: Binary: 2 digits (0 and 1). Decimal: 10 digits (0 – 9). Octal: 8 digits (0 – 7). Hexadecimal: 16 digits (0 – 9 and A – F). The binary system is what used by computers. The decimal system is what used by humans in nature (also called natural number system). Hexadecimal and Octal are a compromise representation between the binary and the decimal. The Hashemite University 3

4 The Hashemite University
Basic Definitions I The number of digits used within a number system is called the Radix or the Base. So: Binary  Base = 2 Octal  Base = 8 Decimal  Base = 10 Hexadecimal  Base = 16 The point in the number, i.e. fractional number, is called radix point. so, based on the radix or base you call it, e.g. in decimal you call it decimal point and in binary you call it binary point. The used digits in each numbering system are borrowed from the decimal system and completed by the alphabet characters (capital letters). In other words, you are able to use the numerals 0-9 and the alphabets A-Z based on the number of digits you need. Then you pick the wanted number of digits in order. The Hashemite University 4

5 The Hashemite University
Basic Definitions II For binary, you need two digits, starting from the numerals set (i.e. 0-9) you get 0 and 1 (just two digits). E.g For octal, you need 8 digits, following the same approach you get the digits 0-7. E.g. 756. For decimal, you need 10 digits then you get 0-9. E.g. 190. For hexadecimal you need 16 digit, starting by the numerals you get 0-9 but still you need an additional 6 digits. For this purpose you move to the alphabet letters and pick 6 letters, so you get A-F. E.g. AD4. In decimal these letters correspond to the following: A  10 B  11 C  12 D  13 E  14 F  15 The Hashemite University 5

6 The Hashemite University
Basic Definitions III To differentiate between numbers from the different numbering systems use one of the following: Add a subscript of the base to the number. e.g: ( )2  Binary (176)8  Octal (AD23)16  Hexadecimal Add the following letters at the end of the number: B (Binary), Q (Octal), nothing for Decimal, H (Hexa). E.g B The universal approach to represent hexadecimal numbers is to start it with a 0 and append ‘h’ to the end of the number. E.g. 0Dh. A less common approach to represent binary and hexadecimal numbers is to proceed the number with a: % for binary $ for hexadecimal e.g. %101001, $AD5 Any number proceeded by ‘0x’ is a hexadecimal number. Such representation is most commonly used in programming languages such as C++. The Hashemite University 6

7 The Hashemite University
Basic Definitions IV Every number in any numbering system can be represented as a weighted sum or a power series of the system radix. The coefficient of each term in the series is the digit value where the power of the base of that term depends on the location of the digit within the number with respect to the radix point (left or right). E.g.: (1890)10 = 1x x x x100 (45.678)10 = 4x101+5x100+6x10-1+7x10-2+8x10-3 (ADF)16 = 10x x x160 Note: the result of this power series is the decimal equivalent of the original number as we will see later. The Hashemite University 7

8 The Hashemite University
Basic Definitions V In computer hardware the following are used: Bit = 0 or 1 Nibble = 4 bits. Byte = 8 bits Word = 2 byte = 16 bits 210 = 1 Kilo = 1024 220 = I Mega 230 = 1 Giga 240 = 1 Tera 1 keyboard character needs 1 byte to store its value. Every thing in computers is power of 2. The architecture of the computer is determined based on its word length, e.g. 32 bit or 64 bit architecture. The Hashemite University 8

9 The Hashemite University
Basic Definitions VI The least significant bit (LSB) is the bit or digit that is located on the right most location within a number. The most significant bit (MSB) is the bit that is located on the leftmost position within a number. E.g.: for the number , 1 is the MSB and 9 is the LSB. The Hashemite University 9

10 Why binary system for computers?
Computers are comprised basically of switches. Switches have only tow states: either ON or OFF. As we learned, such states can be represented as two values: 1 and 0. So it is binary since there are two values and each value needs one digit or bit to represent and store it. The Hashemite University 10

11 Why decimal system for humans?
Created with human history on earth and evolved from nature. Easy to understand. Compact: need small number of digits to represent large values. Also, humans have invented shorthand or abbreviations to simplify large decimal numbers representation to enhance readability, such as million, billion, trillion, etc. The Hashemite University 11

12 Conversion Between Binary and Decimal I
From Binary to Decimal: Expand the binary number in a power series and sum the terms as shown previously. The same method is used when there is a radix point in the number. This method can be used to convert from any base to decimal. Examples: the binary value represents : = 1x27 + 1x26 + 0x25 + 0x24 + 1x23 + 0x22 + 1x21 + 0x20 = 1x x64 + 0x32 + 0x16 + 1x8 + 0x4 + 1x2 + 0x1 = =202 The Hashemite University 12

13 Conversion Between Binary and Decimal II
From Decimal to Binary: Here there are two cases: integer decimal numbers and fraction (floating point) decimal numbers. For integer decimal numbers, there are two methods: 1-Repeated Division By 2 For this method, divide the decimal number by 2, If the remainder is 0, on the right side write down a 0. If the remainder is 1, write down a 1. Repeat the division with the result (new quotient). This process is repeated till the quotient becomes 0. When performing the division, the remainders which will represent the binary equivalent of the decimal number are written beginning at the least significant digit (right) and each new digit is written to more significant digit (the left) of the previous digit. The Hashemite University 13

14 Integer Decimal to Binary – First Method -- Example
57 / 2 = 28, remainder = 1 (binary number will end with 1) 28 / 2 = 14, remainder = 0 14 / 2 = 7, remainder = 0 7 / 2 = 3, remainder = 1 3 / 2 = 1, remainder = 1 1 / 2 = 0, remainder = 1 (binary number will start with 1) Therefore, collecting the remainders, 5710 = The Hashemite University 14

15 Integer Decimal to Binary – Second Method
2- Sum on the fly List the powers of 2 starting from 0 power where you stop at the maximum power less than the number you want to convert. See which of these powers must be included in the sum that will have the result of the decimal number that you want to convert. These powers will have 1 in its position and the powers that are not used will have 0. This method is suitable for small to mid size numbers. The Hashemite University 15

16 Integer Decimal to Binary – Second Method -- Example
Example: convert 5710 to binary Answer = 25 24 23 22 21 20 32 16 8 4 2 1 The Hashemite University 16

17 Fraction Decimal to Binary
As for integers, for fraction decimal numbers we use the following method: Repeated Multiplication By 2 For this method, multiply the decimal number by 2, If the integer part of the result is 0, on the right side write down a 0. If the integer part of the result is 1, write down a 1. Then remove the integer part from the result and repeat the multiplication by 2 for the fraction part. This process is repeated till the fraction becomes 0 or till you reach the sufficient accuracy. When performing the multiplication, the integers which will represent the binary equivalent of the decimal fraction are written beginning from the right of the decimal point and each new digit is written to less significant digit (the right) of the previous digit. Could be unending!!!!! The Hashemite University 17

18 Fraction Decimal to Binary -- Example
Example: convert to binary. 0.3 * 2 = 0.6  integer part = 0 0.6 * 2 = 1.2  integer part = 1 0.2 * 2 = 0.4  integer part = 0 0.4 * 2 = 0.8  integer part = 0 0.8 * 2 = 1.6  integer part = 1 0.6 * 2 = 1.2  integer part = 1, etc. Answer = The Hashemite University 18

19 The Hashemite University
Notes The same methods used to convert from decimal (integer or fraction) to binary are used to convert from decimal to any other base. Just change the radix or base value that you use in the multiplication or in the division. When you face a number that have both integer and fraction parts, e.g or , convert each part alone and then combine them. The Hashemite University 19

20 Why to introduce the hexadecimal and the octal (I)?
Middle approach between binary and decimal systems: Binary is a must by computers but it is verbose, i.e. need large number of bits to represent small quantities, e.g needs 8 bits in binary. Decimal is preferred by humans, easy to understand and compact (needs small number of bits to represent values). Conversion between binary and decimal (especially decimal to binary) is not trivial and expensive in terms of the needed resources. The Hashemite University 20

21 Why to introduce the hexadecimal and the octal (II)?
To keep commonality with binary system, ease of conversion, and the compact feature we need another number system whose base is a power of 2. Base 4 is not compact, however, base 8 (octal) and base 16 (hex) have this feature where base 16 is the most common. From here the hexadecimal system have been introduced to be a middle approach between binary, where it is easy to convert between hexa and binary, as we will see, and the compactness feature as decimal. Recall that computers store data in binary. However, hexa is commonly used in computers to represent locations (addresses) in data storage, in data access, and in RAM. The Hashemite University 21

22 Conversion Between Binary and Octal
The octal has a base = 8 which is 2 raised to power 3. In other words, each digit in the octal system can substitute for 3 bits in the binary system. Such observation is utilized in the conversion process between octal and binary. The Hashemite University 22

23 Binary to Octal Conversion
Start from the radix point to the left and to the right and do the following: Group the binary bits found in the binary number into groups consist of 3 bits. Substitute each group with the octal digit that represents the same quantity represented by the binary group. The same process are used with the bits on the right of the radix point (i.e. fraction). The Hashemite University 23

24 Binary to Octal Conversion - Example
Convert the following number into octal: Answer = The Hashemite University 24

25 Octal to Binary Conversion
Just repeat the inverse of the process used to convert from binary to octal. In other words, substitute each octal digit with its 3 bit binary equivalent. Example: convert to binary. Answer = The Hashemite University 25

26 Octal to Decimal Conversion
From Octal to Decimal: Use the power series expansion method with the base = 8. Example: convert to decimal. = 6x82 + 7x81 + 5x80 + 5x x8-2 = The Hashemite University 26

27 Integer Decimal to Octal Conversion
From Integer Decimal to Octal: Use the repeated division method used in converting from decimal to binary but the difference here is that you divide by 8 (radix value) instead of 2. The Hashemite University 27

28 Integer Decimal to Octal Conversion - Example
Convert (44978)10 to Octal Answer = Division Quotient Remainder 44978 / 8 5622 2 5622 / 8 702 6 702/8 87 87/8 10 7 10/8 1 1/8 The Hashemite University 28

29 Fraction Decimal to Octal Conversion
Repeated Multiplication By 8 For this method, multiply the decimal number by 8. Write down the integer part of the result. Then remove the integer part from the result and repeat the multiplication by 8 for the fraction part. This process is repeated till the fraction becomes 0 or till you reach the sufficient accuracy. When performing the multiplication, the integers which will represent the octal equivalent of the decimal fraction are written beginning from the right of the decimal point and each new digit is written to less significant digit (the right) of the previous digit. Could be unending!!!!! The Hashemite University 29

30 Fraction Decimal to Octal Conversion - Example
Example: convert to octal. 0.356 * 8 =  integer part = 2 0.848 * 8 =  integer part = 6 0.784 * 8 =  integer part = 6 0.272 * 8 =  integer part = 2 0.176 * 8 =  integer part = 1 0.408 * 8 =  integer part = 3, etc. Answer = The Hashemite University 30

31 Conversion Between Binary and Hexadecimal
The Hexa has a base = 16 which 2 raised to power 4. In other words, each digit in the hexa system can substitute for 4 bits in the binary system. Similar to octal, such observation is utilized in the conversion process between hexa and binary. The Hashemite University 31

32 Binary to Hexa Conversion
Start from the radix point to the left and to the right and do the following: Group the binary bits found in the binary number into groups consist of 4 bits. Substitute each group with the Hexa digit that represents the same quantity represented by the binary group. The same process are used with the bits on the right of the radix point (i.e. fraction). The Hashemite University 32

33 Binary to Hexa Conversion - Example
Convert the following number into Hexa: A F B E16 Answer = 25AF.BE16 The Hashemite University 33

34 Hexa to Binary Conversion
Just repeat the inverse of the process used to convert from binary to hexa. In other words, substitute each hexa digit with its 4 bit binary equivalent. Example: convert 56D.4216 to binary. D Answer = The Hashemite University 34

35 Hexa to Decimal Conversion
From Hexa to Decimal: Use the power series expansion method with the base = 16. Example: convert 67B.5116 to decimal. = 6x x x x x16-2 = The Hashemite University 35

36 Integer Decimal to Hexa Conversion
From Integer Decimal to Hexa: Use the repeated division method used in converting from decimal to binary but the difference here is that you divide by 16 (radix value) instead of 2. The Hashemite University 36

37 Integer Decimal to Octal Conversion - Example
Example: Convert to hexa 35243 / 16 = 2202, remainder = 11 ï‚® B (hex number will end with B) 2202 / 16 = 137, remainder = 10 ï‚® A 137 / 16 = 8, remainder = 9 8 / 16 = 0, remainder = 8 (hex number will start with 8) Therefore, collecting the remainders, = 89AB16 The Hashemite University 37

38 Fraction Decimal to Octal Conversion
Repeated Multiplication By 16 For this method, multiply the decimal number by 16. Write down the integer part of the result. Then remove the integer part from the result and repeat the multiplication by 8 for the fraction part. This process is repeated till the fraction becomes 0 or till you reach the sufficient accuracy. When performing the multiplication, the integers which will represent the hexa equivalent of the decimal fraction are written beginning from the right of the decimal point and each new digit is written to less significant digit (the right) of the previous digit. Could be unending!!!!! The Hashemite University 38

39 Fraction Decimal to Octal Conversion - Example
Example: convert to hexa. 0.356 * 16 =  integer part = 5 0.696 * 16 =  integer part = B 0.136 * 16 =  integer part = 2 0.176 * 16 =  integer part = 2 0.816 * 16 =  integer part = D 0.056 * 16 =  integer part = 0, etc. Answer = 0.5B22D0...16 The Hashemite University 39

40 Conversion Between Octal and Hexadecimal
From octal to hexadecimal: First convert from octal to binary then convert the result from binary to hexadecimal. From hexadecimal to octal: First convert from hexa to binary then convert the result from binary to octal. The Hashemite University 40

41 The Hashemite University
Additional Notes This lecture covers the following material from the textbook: Chapter 1: Sections 1.2 – 1.4 The Hashemite University 41


Download ppt "Digital Logic Lecture 2 Number Systems"

Similar presentations


Ads by Google