Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM.

Similar presentations


Presentation on theme: "© Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM."— Presentation transcript:

1 © Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM

2 © Prepared By: Razif Razali 2 CONTENTS Introduction To Numbering SystemIntroduction To Numbering System Converting between decimal and othersConverting between decimal and others Converting binary and othersConverting binary and others Converting between octal and hexadecimal to othersConverting between octal and hexadecimal to others Arithmetic operationArithmetic operation One’s complement and two’s ComplementOne’s complement and two’s Complement

3 3 Fundamental to understand how computers work is understanding the number system that computer use to store data and communicate with each other.Fundamental to understand how computers work is understanding the number system that computer use to store data and communicate with each other. Number system been used to understand computer:Number system been used to understand computer: –Base 10 (decimal) E.g.: 3945 10 / 3945d –Base 2 (binary) E.g.: 10101011 2 / 10101011b –Base 8 (octal) E.g. : 653 8 –Base 16 (hexadecimal) E.g.: 0A3E 16 / 0A3Eh Number Systems

4 4 The Decimal System In everyday life we use a system based on decimal digits.In everyday life we use a system based on decimal digits. Consider the number 4728 means four thousands, seven hundreds, two tens, plus eight:Consider the number 4728 means four thousands, seven hundreds, two tens, plus eight: 4728 = (4 x 1000) + (7 x 100) + (2x10) + 8 The decimal system is said to have a base or radix of 10.The decimal system is said to have a base or radix of 10. Each digit in the number is multiplied by 10 raised to a power corresponding to that digit’s position:Each digit in the number is multiplied by 10 raised to a power corresponding to that digit’s position: 4728 = (4 x 10 3 ) + (7 x 10 2 ) + (2 x 10 1 ) + (8 x 10 0 )

5 5 The Binary System  In the binary system, we have only two digits, 1 and 0.  Thus, number in the binary system are represented to the base 2.  Each digits in a binary number also have a value depending on its position: 100 2 = (1 x 2 2 ) + (0 x 2 1 ) + (0 x2 0 ) = 4 10 101011b = (1 x 2 5 ) + (0 x 2 4 ) + (1 x 2 3 ) + (0 x 2 2 ) + (1 x 2 1 ) + (1 x 2 0 ) = 43d

6 Binary Numbering Scale Base 2 NumberBase 10 EquivalentPowerPositional Value 00002020 1 00112121 2 01022 4 01132323 8 10042424 16 10152525 32 11062626 64 11172727 128

7 Binary Numbers Each binary digit (called bit) is either 1 or 0Each binary digit (called bit) is either 1 or 0 Bits have no inherent meaning, can representBits have no inherent meaning, can represent –Unsigned and signed integers –Characters –Floating-point numbers –Images, sound, etc. Bit NumberingBit Numbering –Least significant bit (LSB) is rightmost (bit 0) –Most significant bit (MSB) is leftmost (bit 7 in an 8-bit number) 10011101 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 01234567 Most Significant Bit Least Significant Bit

8 Octal Number System Also known as the Base 8 SystemAlso known as the Base 8 System Uses digits 0 - 7Uses digits 0 - 7 Readily converts to binaryReadily converts to binary Groups of three (binary) digits can be used to represent each octal digitGroups of three (binary) digits can be used to represent each octal digit Also uses multiplication and division algorithms for conversion to and from base 10Also uses multiplication and division algorithms for conversion to and from base 10

9 9 The System The Hexadecimal System  A computer’s world is a binary world and communication of instruction and data by the devices that process them is always in binary. Ø Binary system is very difficult for human being. ØHuman being are comfortable to decimal number system. ØHowever calculations to convert binary to decimal are relatively complex. ØA notation known as hexadecimal has been adopted. ØBinary digits are grouped into sets of four. ØEach possible combination of four binary digits is given a symbol (hexadecimal digits) as follows:

10 10 The System The Hexadecimal System 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

11 11 The Hexadecimal System  In the hexadecimal system, we have 16 hexadecimal digits.  Thus, number in the hexadecimal system are represented to the base 16.  Each digits in a hexadecimal number also have a value depending on its position: Example:  2C 16 = (2 x 16 1 )+ (C x 16 0 )  = (2 x 16 1 )+ (12 x 16 0 )  = 44 10  The reason for using hexadecimal notation are because it is more compact than binary notation and it is extremely easy to convert between binary and hexadecimal.

12 12 Number System DecimalBinaryOctalHexadecimal 000000000 100010011 200100102 300110113 401001004 501011015 601101106 701111117 81000-8 91001-9 101010-A 111011-B 121100-C 131101-D 141110-E 151111-F

13 13 Conversion Between Number Systems Converting Binary to DecimalConverting Binary to Decimal Converting Binary to OctalConverting Binary to Octal Converting Binary to HexConverting Binary to Hex Converting Decimal to BinaryConverting Decimal to Binary Converting Decimal to OctalConverting Decimal to Octal Converting Decimal to HexConverting Decimal to Hex Converting Octal to BinaryConverting Octal to Binary Converting Octal to DecimalConverting Octal to Decimal Converting Octal to HexConverting Octal to Hex Converting Hex to BinaryConverting Hex to Binary Converting Hex to DecimalConverting Hex to Decimal Converting Hex to OctalConverting Hex to Octal

14 14 101001b to decimal101001b to decimal 101001b = (1 x 2 5 ) + (0 x 2 4 ) + (1 x 2 3 ) + (0 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) = 32 + 0 + 8 + 0 + 0 + 1 = 41d Converting Binary to Decimal

15 Binary to Decimal Conversion The easiest method for converting a binary number to its decimal equivalent is to use the Multiplication AlgorithmThe easiest method for converting a binary number to its decimal equivalent is to use the Multiplication Algorithm Multiply the binary digits by increasing powers of two, starting from the rightMultiply the binary digits by increasing powers of two, starting from the right Then, to find the decimal number equivalent, sum those productsThen, to find the decimal number equivalent, sum those products

16 Multiplication Algorithm Convert (10101101) 2 to its decimal equivalent: Binary 1 0 1 0 1 1 0 1 Positional Values x xxxxxxx 2020 21212 2323 2424 2525 2626 2727 128 + 32 + 8 + 4 + 1 Products 173 10

17 Binary to Decimal (Real number) Convert the following binary to decimal:Convert the following binary to decimal: a)0.11 2 b)1.101 2 c)101.11 2 © Prepared By: Razif Razali 17

18 Binary to Hexadecimal Conversion The easiest method for converting binary to hexadecimal is to use a substitution codeThe easiest method for converting binary to hexadecimal is to use a substitution code Each hex number converts to 4 binary digitsEach hex number converts to 4 binary digits

19 Convert 010101101010111001101010 2 to hex using the 4-bit substitution code : 0101 0110 1010 1110 0110 1010 Substitution Code 5 6 A E 6 A 56AE6A 16

20 Converting Binary to Hexadecimal  Each hexadecimal digit corresponds to 4 binary bits  Example: Convert the 32-bit binary number to hexadecimal 1110 1011 0001 0110 1010 0111 1001 0100  Solution: 0100 4 1001 9 0111 7 1010 A 0110 6 0001 1 1011 B 1110 E

21 Converting from binary to hexadecimal To convert from binary to hexadecimalTo convert from binary to hexadecimal 1. Organize the stream of binary digits into groups of four. 2. Find the hexadecimal value for each group of 4 bits. 10010010111000011010 9 2 E 1 A Example: 1111110011100100

22 22 Decimal can be converted in to a binary systems with the Remainder MethodDecimal can be converted in to a binary systems with the Remainder Method Example: Convert 26d to base 2Example: Convert 26d to base 2 => 26d = 11010b 26/2 = 13 0 13/2 = 6 1 6/2 = 3 0 3/2 = 1 1 1/2 = 0 1 Most significant bit Least significant bit Converting Decimal to Binary

23 23 How about floating point number?How about floating point number? E.g.: Convert 0.875d into base 2 number.E.g.: Convert 0.875d into base 2 number. => 0.875d = 0.1110b 0.875 x 2 = 1.751 0.75 x 2 = 1.51 0.5 x 2 = 1.01 0 x 2 = 0 0 Converting Decimal to Binary (Floating point number)

24 24 How about floating point number?How about floating point number? E.g 2.: Convert 0.442d into base 2 number.E.g 2.: Convert 0.442d into base 2 number. 0.072 x 2 = 0.144 0 0.144 x 2 = 0.288 0 => 0.875d = 0.1110b 0.442 x 2 = 0.8840 0.884 x 2 = 1.7681 0.768 x 2 = 1.5361 0.536 x 2 = 1.072 1 Converting Decimal to Binary (Floating point number)

25 25 Decimal can be converted into a hex with the Remainder MethodDecimal can be converted into a hex with the Remainder Method Example: Convert 425d to base 16Example: Convert 425d to base 16 –425 / 16 = 26 9 -> 9 – 26 / 16 = 1 10 -> A – 1 / 16 = 0 1 -> 1 => 425d = 1A9h Example: Convert 374d to base 16Example: Convert 374d to base 16 –374 / 16 = 23 6 -> 6 – 23 / 16 = 1 7 -> 7 – 1 / 16 = 0 1 -> 1 => 374d = 176h Converting Decimal to Hex

26 Decimal to Octal Conversion Convert 427 10 to its octal equivalent: 427 / 8 = 53 R 3 Divide by 8; R is LSD 53 / 8 = 6 R 5 Divide Q by 8; R is next digit 6 / 8 = 0 R 6 Repeat until Q = 0 653 8

27 Octal to Decimal Conversion Convert 653 8 to its decimal equivalent: 6 5 3 xx x 8 2 8 1 8 0 384 + 40 + 3 427 10 Positional Values Products Octal Digits

28 Octal to Binary Conversion Each octal number converts to 3 binary digits To convert 653 8 to binary, just substitute code: 6 5 3 110 101 011

29 Substitution code can also be used to convert binary to octal by using 3-bit groupings: 010 101 101 010 111 001 101 010 Substitution Code 2 5 5 2 7 1 5 2 25527152 8

30 30 To convert a hex number to binary, we need only express each hex digit in binaryTo convert a hex number to binary, we need only express each hex digit in binary E.g.: Convert DE1 16 to binaryE.g.: Convert DE1 16 to binary D E 1 D E 1 = 1101 1110 0001 = 1101 1110 0001 = 110111100001b = 110111100001b To go from binary to hex, just reverse this processTo go from binary to hex, just reverse this process 10010001 2 = 1001 0001 = 91 16 Converting Between Hex and Binary

31 31 Converting Hex to Decimal Ø A3F 16 to decimal A3F 16 = (A x 16 2 ) + (3 x 16 1 ) + (F x 16 0 ) = (10 x 256) + (3 x 16) + (15 x 1) = 2623 10

32 EXERCISE Convert the following numbers: a)1234 16 to Decimal b)3BA4 16 to Decimal c)10011101 2 to Decimal d)422d to Hexadecimal © Prepared By: Razif Razali 32

33 1.Show the hexadecimal equivalent of the bit pattern 1100 1110 0010. 2.Show the hexadecimal equivalent of the bit pattern 0011100010. 3.What is the bit pattern for 2675 base 16? 4.What is the bit pattern for B51E base 16? Exercises 1

34 Exercise 2 a)Convert 10 0110 2 to decimal. b)Convert 3B2 16 to decimal. c)Convert 370 8 to decimal.

35 Exercise 3 Convert the following to decimal: 1.144 8 _______ 2.6A 16 _______ 3. 100 2 _______

36 Table 2.1 shows a summary of the four positional number systems discussed in this chapter. Summary of the four positional systems

37 37 Integer Representation For the purpose of computer storage and processing, only binary digits (0 and 1) may be used to represent numbers (negative or positive).For the purpose of computer storage and processing, only binary digits (0 and 1) may be used to represent numbers (negative or positive). For a 8-bit number, there are 2 8 =256 possible bit patterns.For a 8-bit number, there are 2 8 =256 possible bit patterns. For unsigned number, we can represent 0 to 255 using 8-bit number.For unsigned number, we can represent 0 to 255 using 8-bit number. For signed number, the most significant (leftmost) bit usually used as a sign bit.For signed number, the most significant (leftmost) bit usually used as a sign bit. –0 for positive number. –1 for negative number. 11110110 00001010 Sign bit Negative Positive

38 38 Integer Representation ØThere are several alternative conventions used to represent negative integers. ØSome of them are:  Signed magnitude  One’s complement  Two’s complement

39 39 Signed Magnitude Also know as “sign and magnitude,” the leftmost bit is the sign and the rest are magnitudeAlso know as “sign and magnitude,” the leftmost bit is the sign and the rest are magnitude –0 = positive –1 = negative SignMagnitude Integer Representation

40 40 Example (for 8-bit number)Example (for 8-bit number) –+25d =0 0011001b –-25d=1 0011001b Largest number is +127 and smallest number is – 127Largest number is +127 and smallest number is – 127 Problems: Two representations for zero:Problems: Two representations for zero: –+0= 00000000b –-0=10000000b Integer Representation Signed Magnitude (cont.)

41 41 One’s Complement The leftmost bits is the sign ( 0 = +ve, 1 = -ve)The leftmost bits is the sign ( 0 = +ve, 1 = -ve) Negative number is obtained by complementing each bit from 0 to 1 or from 1 to 0Negative number is obtained by complementing each bit from 0 to 1 or from 1 to 0 Example (8-bit number):Example (8-bit number): –+25d = 00011001b –-25d =11100110b Two representation of zero:Two representation of zero: +0d = 00000000b and -0d = 11111111 Largest number is +127 and smallest number is -127Largest number is +127 and smallest number is -127 Integer Representation

42 One’s complement –Switch all 0’s to 1’s and 1’s to 0’s Binary #10110011 1’s complement01001100

43 43 The leftmost bit is the sign bit (0= +ve, 1 = -ve)The leftmost bit is the sign bit (0= +ve, 1 = -ve) Negative of the number is obtained by adding 1 to the one’s complement negative.Negative of the number is obtained by adding 1 to the one’s complement negative. Example(8-bit number):Example(8-bit number): –+25d=00011001b –-25d=11100111b One representation for zero: 0000000bOne representation for zero: 0000000b Largest number is +127 and smallest number is -128Largest number is +127 and smallest number is -128 Two’s complement Integer Representation

44 Two’s Complement –Step 1: Find 1’s complement of the number Binary #11000110 1’s complement00111001 –Step 2: Add 1 to the 1’s complement 00111001 + 00000001 00111010

45 Example Convert +5 into two’s complement representation and give the answer in 8 bits.Convert +5 into two’s complement representation and give the answer in 8 bits. Solution:Solution: –Obtain +5 representation = 0000 0101 –Obtain one’s complement= 1111 1010 –Add 1 to one’s complement= 1111 1010 + 1 = 11111011 – -5 in two’s complement is 1111 1011 © Prepared By: Razif Razali 45

46 Exercise Get the representation of two’s complement for the following numbers (by using 6 bit)Get the representation of two’s complement for the following numbers (by using 6 bit) a.+7 b.-20 © Prepared By: Razif Razali 46

47 Example Interpret 10111011 in decimal if the number was stored as a sign-and-magnitude integerInterpret 10111011 in decimal if the number was stored as a sign-and-magnitude integer Solution:Solution: –Ignoring the leftmost bit, the remaining bits are 0111011. This number in decimal is 59. The leftmost bit is 1, so the number is –59.

48 Binary Arithmetic Addition (+)Addition (+) –0 + 0 = 0 –0 + 1 = 1 –1 + 0 = 1 –1 + 1 = 10 Example:Example: –010111 + 011110 = 110101 –100011 + 011100 = 111111 © Prepared By: Razif Razali 48

49 Binary Addition Start with the least significant bit (rightmost bit)Start with the least significant bit (rightmost bit) Add each pair of bitsAdd each pair of bits Include the carry in the addition, if presentInclude the carry in the addition, if present 00011101 00110110 + (54) (29) (83) 1 carry 01234bit position:567 11 1 01010011

50 Binary Arithmetic SubtractionSubtraction –0 - 0 = 0 –0 - 1 = 1(borrow 1) –1 - 0 = 1 –1 – 1 = 0 ExampleExample –010111 – 011110 = 100001 –100011 – 011100 = 000011 © Prepared By: Razif Razali 50

51 Binary Arithmetic MultiplicationMultiplication –0 x 0 = 0 –0 x 1 = 0 –1 x 0 = 0 –1 x 1 = 1 © Prepared By: Razif Razali 51

52 Binary Arithmetic DivisionDivision –0 / 1 = 0 –1 / 1 = 0 © Prepared By: Razif Razali 52

53 Arithmetic Operation Arithmetic's operation can be done by usingArithmetic's operation can be done by using –One’s complement –Two’s complement –Sign and Magnitude © Prepared By: Razif Razali 53

54 Arithmetic Operation

55 Sign And Magnitude All subtraction operation will be changed into addition operation.All subtraction operation will be changed into addition operation. ExampleExample 8 – 5 = 8 + (-5) -10 + 2 = (-10) + 2 6 – (-3) = 6 + 3 © Prepared By: Razif Razali 55

56 Example If sign of both number are negativeIf sign of both number are negative Assume we have -3 – 4Assume we have -3 – 4 Solution:Solution: –Step 1 -3 – 4 = (-3) + (-4) = 100011 + 100100 -Step 2 Only add the magnitude  00011 + 00100 = 00111 -Step 3 Set the sign bit of the result to –ve (add 1 to MSB) 100111 = -7 10 © Prepared By: Razif Razali 56

57 Example If sign of both number differIf sign of both number differ Assume (-2) + (+4)Assume (-2) + (+4) SolutionSolution –Step 1 (get the binary pattern) 100010 + 000100 –Step 2 Change the sign bit of the –ve number to +ve 100010  000010 –Step 3 (get the result) 000100 - 000010 000010 = 2 10 © Prepared By: Razif Razali 57

58 Example (+3) + (-5) = 000011 + 100101 = 100101 – 000011 = 100010 = -2 © Prepared By: Razif Razali 58

59 One’s Complement In One’s complement, it is easier than sign-magnitude.In One’s complement, it is easier than sign-magnitude. However a situation called overflow might occur when addition is performed on the following categories:However a situation called overflow might occur when addition is performed on the following categories: –If both are negative numbers –If both are in difference sign © Prepared By: Razif Razali 59

60 Example Assume we have - 3 - 4 find the value by using 8 bit. (-3) + (-4) Step 1: Convert -3 and -4 into 1’ complement +3  00000011 (8 bit) Implement 1’ complement  11111100 +4  00000100  11111011 © Prepared By: Razif Razali 60

61 Example Step 2: Perform the addition operation -3 = 1111 1100 -3 = 1111 1100 + -4 = +1111 1011 ------------------------------ -7 = 111110111 (9 bit) © Prepared By: Razif Razali 61 Overflow occur and needs to be add to rightmost bit

62 Example Step 3 11110111 + 1 + 1-------------- 11111000 = -7 © Prepared By: Razif Razali 62 Answer

63 63 For n bit number, highest integer value can be represent is 2 n-1 -1.For n bit number, highest integer value can be represent is 2 n-1 -1. Highest valueLowest Value Signed Magnitude2 n-1 -1-(2 n-1 -1) One’s Complement2 n-1 -1-(2 n-1 -1) Two’s Complement2 n-1 -1-(2 n-1 ) Range in Integer Representation


Download ppt "© Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM."

Similar presentations


Ads by Google