Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numbering systems.

Similar presentations


Presentation on theme: "Numbering systems."— Presentation transcript:

1 Numbering systems

2 Understand and identify a few of the coding systems .
Learning Objectives Understand and identify a few of the coding systems .

3 Data and Program Representation
Digital computers: Can only understand two states, off and on (0 and 1) Digital data representation: The process of representing data in digital form so it can be understood by a computer

4 Digital Data Representation
Bit: The smallest unit of data that a binary computer can recognize (a single 1 or 0) Byte = 8 bits , Nibble =4 bits Byte terminology used to express the size of documents and other files, programs, etc. Prefixes are often used to express larger quantities of bytes: kilobyte (KB), megabyte (MB), gigabyte (GB), terabyte (TB), etc.

5 Quiz I have a 2 Gb Flash memory. How many 512Kb files can I store on the Flash memory? Answer Convert 2Gb to Kb 2x1024=2048Mb Convert from Mb to Kb 2048x1024= kb Number of files= / 512 = 4096 file Note Mb is in common use for Megabit e.g. 200Megabit = 200Mb MB is in common use for Megabyte , e.g. 200MegaByte=200MB 5

6 Numbering Systems A numbering system is a way of representing numbers.
A number is represented as a string of digits, e.g., a number N with n digits represented by sequence dn-1, …, d1,d0

7 Numbering Systems Positional notation
A system of expressing numbers in which the digits are arranged in succession, the position of each digit has a place value, and the number is equal to the sum of the products of each digit by its place value . Determination of a number require the following : The digits or symbols; The positional of the digit in the number; The base of the number system.

8 Numbering Systems Base ( radix )
The base of a number system is simply the number of different digits, including zero that exist in the number system. A number system of radix r, typically has a set of r allowed digits belongs to {0,1,…, r-1} We write a number N in the number system of radix r by expressing it in the form (N)r or Nr (12) and 2 are digits in base 10, and 3 are digits in base 5 i.e., belongs to {0,1,..,4}

9 Numbering Systems a radix point is the symbol used in numerical representations to separate the integer part of a number (to the left of the radix point) from its fractional part (to the right of the radix point). Ex , 13 is the integer to the left of the radix point, and 625 (i.e. 625/1000) is the fractional part to the right.

10 Understanding Decimal Numbers
The numbering system we commonly use called the decimal numbering system because it uses 10 digits - symbols - (0,1,2,…,9) to represent all possible numbers. Why do we use 10 digits, anyway? Numbers greater than nine such as 7216 represented using combination of these 10 digits.

11 Understanding Decimal Numbers
Decimal numbers are made of decimal digits: (0,1,2,3,4,5,6,7,8,9) But how many items does a decimal number represent? 8653 = 8x x x x100 What about fractions? = 9x x x x x x x10-2 In formal notation -> ( )10

12

13 Understanding Octal Numbers
Octal numbers are made of octal digits: (0,1,2,3,4,5,6,7) How many items does an octal number represent? (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (1362)10 What about fractions? (465.27)8 = 4x82 + 6x81 + 5x80 + 2x x8-2 Octal numbers don’t use digits 8 or 9

14 Understanding Binary Numbers
Binary numbers are made of binary digits (bits): 0 and 1 How many items does an binary number represent? (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10 What about fractions? (110.10)2 = 1x22 + 1x21 + 0x20 + 1x x2-2

15

16 Understanding Hexadecimal Numbers
Hexadecimal numbers are made of 16 digits: (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) How many items does an hex number represent? (3A9F)16 = 3x x x x160 = What about fractions? (2D3.5)16 = 2x x x x16-1 = Note that each hexadecimal digit can be represented with four bits. (1110) 2 = (E)16 Groups of four bits are called a nibble. (1110) 2

17 Representing Numerical Data
Least Significant Digit (LSD) is the right most digit has the lowest value Most Significant Digit (MSD) is the left most digit has the highest value The most significant symbol can not be zero Example: Show how the value of the number (9375)10 is estimated 1 2 3 position 100 101 102 103 Weight 5 7 9 Digit 9375 5x1 7x10 3x100 9x1000 Value 5 is the least significant digit (LSD) 9 is the most significant digit (MSD)

18 Representing Numerical Data
Commonly used numbering systems Decimal number system base =10, Ten allowed digits{0,1,…,9} Binary number system base= 2, Two allowed digits {0,1} A Binary digit is referred to as Bit Most significant Bit (MSB) is the leftmost bit has the highest value Least significant Bit (LSB) is the rightmost bit has the lowest value C. Octal number system base =8, Eight allowed digits {0,1,2,…,7} D. Hexadecimal number system base = 16, Sixteen allowed digits {0,1,…,9, A,B,C,D,E,F} Where, A= ten , B= eleven, C=Twelve, D= thirteen, E=fourteen, F= fifteen Q. Why is the digit following 9 assigned the character A not 10 ? Ans. What we need is a single digit whose value is ten but “10” is actually two digits. Thus, in hexadecimal system the two digits number (10)16 actually represents a value of sixteen not ten

19 digit in the number system)
Check point Q. What is the largest value can be represented in three integral digits? For the decimal system, it is (- - - )10 For the octal system, it is (- - - )8 For the hex system, it is (- - - )16 For the binary system, it is (- - - )2 Hint (The largest value results when all 3 positions are filled with the largest digit in the number system) Answer For the decimal system, it is ( 999 )10 For the octal system, it is ( )8 For the hex system, it is ( fff )16 For the binary system, it is ( 111 )2

20 Conversion Between Number Bases
Hexadecimal (base16) Decimal(base 10) Octal(base 8) Binary(base 2) Learn to convert between bases.

21 Representing Numerical Data
Converting between numbering systems Converting from decimal to any base Converting from any base to decimal Converting from any base to any base A special conversion case number bases that are related (Shortcut method to/from binary )

22 Convert an Integer from Decimal to Another Base
For each digit position: Divide decimal number by the base (e.g. 2) The remainder is the lowest-order digit Repeat first two steps until no divisor remains. Example for (13)10: Integer Quotient Remainder Coefficient 13/2 = ½ a0 = 1 6/2 = a1 = 0 3/2 = ½ a2 = 1 1/2 = ½ a3 = 1 Repeated Division-by-r (for whole numbers) Repeated Multiplication-by- r (for fractions) r is the radix of the number system which we need LSB MSB Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2

23 Repeated Division-by-r
To convert a whole number to the new base r, use successive division by r until the quotient is 0. The remainders form the answer, with the first remainder as LSB or LSD and the last as MSB or MSD. Example: (43)10 = (?)2 (43)10 = (101011)2

24 Convert an Fraction from Decimal to Another Base
For each digit position: Multiply decimal number by the base (e.g. 2) The integer is the highest-order digit Repeat first two steps until fraction becomes zero. Example for (0.625)10: Integer Fraction Coefficient 0.625 x 2 = a-1 = 1 0.250 x 2 = a-2 = 0 0.500 x 2 = a-3 = 1 MSB LSB Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2

25 Repeated Multiplication-by-r
To convert decimal fractions to binary, repeated multiplication by r is used, until the fractional product is 0 (or until the desired number of digits of accuracy obtained). The carried digits, or carries, produce the answer, with the first carry as the MSB or MSD, and the last as the LSB or MSD. Example: (0.3125)10 = (.0101)2

26 Note For a number that has both integral and fractional parts, conversion is done separately for both parts, and then the result is put together with a system point in between both parts.

27 2-Any base r-to-Decimal Conversion
Base-r to decimal: multiply digits with their corresponding weights. Examples ( )2 = 1     = = (13.625)10 (572.6)8 = 5   8-1 = = (378.75)10 Convert 3b216 to decimal. N = 3* * *160 = 94610 Convert 3708 to decimal. N = 3*82 + 7*81 + 0*80 = = 24810

28 3-Conversion between Bases
In general, conversion between bases can be done via decimal: First convert given number to decimal then convert decimal number to the new base. Base-2 Base-2 Base-3 Base-3 Base-4 Decimal Base-4 … …. Base-R Base-R

29 Converting Between Base 16 and Base 2
3A9F16 = 3 A 9 F Conversion is easy! Determine 4-bit value for each hex digit Note that there are 24 = 16 different values of four bits Easier to read and write in hexadecimal. Representations are equivalent! Similarly, it takes one hexadecimal digit to exactly represent 4 bits (i.e., 4bit ~ (d)16).

30 Converting Between Base 16 and Base 8
3A9F16 = 3 A 9 F = 3 5 2 3 7 Convert from Base 16 to Base 2 Regroup bits into groups of three starting from right Ignore leading zeros Each group of three bits forms an octal digit. Since 8=23 , we can represent binary numbers directly in base 8 using one octal digit to correspond to each three binary digits (i.e., 3bit ~ (d)8).

31 A special conversion case number bases that are related (Shortcut method to/from binary )
Grouping of several digits in the smaller number base corresponds exactly to single digit in the larger number base Examples Binary  Octal: Partition in groups of 3 ( )2 = ( )8 Octal  Binary: reverse ( )8 = ( )2 Binary  Hexadecimal: Partition in groups of 4 ( )2 = (5D9.B8)16 Hexadecimal  Binary: reverse (5D9.B8)16 = ( )2

32 Arithmetic operation on numbering systems
Addition Subtraction Multiplication division

33 Decimal Addition Example
Write down 5, carry 1 Add 3758 to 4657: 2) Add = 11 Write down 1, carry 1 1 1 1 3) Add = 14 Write down 4, carry 1 8 4 1 5 4) Add = 8 Write down 8 33

34 Decimal Addition Explanation
What just happened? (carry) (sum) (subtract the base) 1 1 1 So when the sum of a column is equal to or greater than the base, we subtract the base from the sum, record the difference, and carry one to the next column to the left. 34

35 Binary Addition Rules 1 + 1 = 210 = 102 = 0 with 1 to carry
= 0 = 1 = 1 (just like in decimal) = = 102 = 0 with 1 to carry = = 112 = 1 with 1 to carry 35

36 Binary Addition Example 1
Col 1) Add = 1 Write 1 Example 1: Add binary to 11100 Col 2) Add = 1 Write 1 1 1 1 1 Col 3) Add = 2 (10 in binary) Write 0, carry 1 Col 4) Add = 2 Write 0, carry 1 1 1 1 1 Col 5) Add = 3 (11 in binary) Write 1, carry 1 Col 6) Add = 2 Write 0, carry 1 Col 7) Bring down the carried 1 Write 1 36

37 Binary Addition Explanation
What is actually happened when we carried in binary? In the first two columns, there were no carries. In column 3, we add = 2 Since 2 is equal to the base, subtract the base from the sum and carry 1. 1 1 1 1 In column 4, we also subtract the base from the sum and carry 1. 2 3 2 2 In column 5, we also subtract the base from the sum and carry 1. 2 2 2 2 In column 6, we also subtract the base from the sum and carry 1. 1 1 1 1 In column 7, we just bring down the carried 1 37

38 Binary Addition Verification
You can always check your answer by converting the figures to decimal, doing the addition, and comparing the answers. Verification 8310 = = 8310 1 1 1 1 38

39 Binary Addition Example 2
Verification 7310 = = 7310 Example 2: Add 1111 to 1 1 1 1 1 1 1 1 39

40 Decimal Subtraction Example (Borrow method)
Try to subtract 5 – 7  can’t. Must borrow 10 from next column. Subtract 4657 from 8025: Add the borrowed 10 to the original 5. Then subtract 15 – 7 = 8. Try to subtract 1 – 5  can’t. Must borrow 10 from next column. But next column is 0, so must go to column after next to borrow. 7 9 1 1 1 1 Add the borrowed 10 to the original 0. Now you can borrow 10 from this column. 3 3 6 8 Add the borrowed 10 to the original 1.. Then subract 11 – 5 = 6 3) Subtract 9 – 6 = 3 4) Subtract 7 – 4 = 3 40

41 Decimal Subtraction Explanation
3 3 6 8 So when you cannot subtract, you borrow from the column to the left. The amount borrowed is 1 base unit, which in decimal is 10. The 10 is added to the original column value, so you will be able to subtract. 41

42 Binary Subtraction Example 1
Col 1) Subtract 1 – 0 = 1 Example 1: Subtract binary from Col 2) Subtract 1 – 0 = 1 Col 3) Try to subtract 0 – 1  can’t. Must borrow 2 from next column. But next column is 0, so must go to column after next to borrow. 2 1 Add the borrowed 2 to the 0 on the right. Now you can borrow from this column (leaving 1 remaining). 2 2 Add the borrowed 2 to the original 0. Then subtract 2 – 1 = 1 Col 4) Subtract 1 – 1 = 0 1 1 1 1 Col 5) Try to subtract 0 – 1  can’t. Must borrow from next column. Add the borrowed 2 to the remaining 0. Then subtract 2 – 1 = 1 Col 6) Remaining leading 0 can be ignored. 42

43 Binary Subtraction Verification
2310 = = 2310 Subtract binary 11100 from : 2 1 2 2 1 1 1 1 43

44 X = (1151)10 , y = (1102)10 which one is greater than the other ?
Note X = (1151)10 , y = (1102)10 which one is greater than the other ? Ans. Compare each digit from left to right digit 1 in x = digit 1 in y goto the next digit digit 2 in x = digit 2 in y goto the next digit digit 3 in x > digit 3 in y stop x greater than y Quiz: (110101)2 , (11001)2 which one is greater than the other ? 44

45 Binary multiplication
Binary multiplication uses the same technique as decimal multiplication. Example: multiplying 1102 by 102. 110 x 000 + 110 1100 6 x 2 ------ 12 45

46 Division Division rule Set quotient to zero
Repeat while dividend is greater than or equal to divisor Subtract divisor from dividend Add 1 to quotient End of repeat block quotient is correct, dividend is remainder STOP 46

47 Binary division Division as repeated subtraction Example in decimal 84 ÷ 21 = ?? I subtracted 21 four times,  so 84 ÷ 21 = 4 84 − 21 − 21 − 21 − 21 1 ---- 4 47

48 Hence result is 2 and with remainder 2 ( (10)2 )
Example: Find 1100 ÷ 0101 Ans. = 111 = 010 Hence result is 2 and with remainder ( (10)2 ) quotient 1 ----- 2 48

49 One’s Complement and Two’s Complement Representations

50 One’s Complement Representation
The one’s complement of a binary number involves inverting all bits. 1’s comp of is 1’s comp of is

51 Two’s Complement Algorithm 1 – Simply complement each bit and then add 1 to the result. Finding the 2’s complement of ( )2 and of its 2’s complement… N = [N] =

52 Two’s Complement Representation
Algorithm 2 – Starting with the least significant bit, copy all of the bits up to and including the first 1 bit and then complementing the remaining bits. N = [N] =

53 Logical Operation On binary

54 Logical OR Rules OR Operations
OR Results in 1 if either or both of the operands are 1. OR Table 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1

55 Logical OR Operation To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: OR

56 Logical XOR Rules XOR Operations
The exclusive OR. Similar to OR except that it now gives 0 when both its operands are 1. Rules. 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0

57 Logical XOR Examples Ex 1: 1 0 0 1 1 0 0 1 XOR 0 0 0 0 1 1 1 1
Ex 2: XOR

58 Logical AND Rules AND Operations
AND yields 1 only if both its operands are 1. Rules. 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1

59 Logical AND Examples Ex 2: 0 1 1 1 AND 1 0 0 1 0 0 0 1

60 Logical NOT NOT Operations
NOT is a separate operator for flipping the bits. Rules. NOT 0 = 1 NOT 1 =   Example. NOT =

61 Thank you


Download ppt "Numbering systems."

Similar presentations


Ads by Google