1 / 38

Data Representation and Numbering Systems

Data Representation and Numbering Systems. The Decimal Numbering System. In the Decimal system a digit can take one out of ten different values (0..9) A number in the decimal system is expressed by the following expression: Notes:

Download Presentation

Data Representation and Numbering Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Representation and Numbering Systems

  2. The Decimal Numbering System • In the Decimal system a digit can take one out of ten different values (0..9) • A number in the decimal system is expressed by the following expression: • Notes: • A decimal system with N digits can represent the numbers from 0 to 10N-1. • In a decimal system with N digits there are 10N different combinations. • The digit to the right of a number is called the Least Significant Digit (LSD). • The digit to the left of a number is called the Most Significant Digit (MSD). (dndn-1…d1d0)10 = (dnX10n )+ (dn-1X10n-1)+…+ (d1X101)+(d0X100) Where d = {0,1,2,3,4,5,6,7,8,9} = {0..9}

  3. The Binary Numbering System • Digital systems and computers use the Binary system because it has only two states (0 and 1) • A number in the Binary system is expressed by the following expression: Examples: • (1011)2 = (1X23 )+(0X22)+(1X21)+(1X20) = 8+0+2+1= (11)10 • (10110)2 = (1X24 )+(0X23)+(1X22)+(1X21)+(0X20) = 16+0+4+2+0= (22)10 • (101100)2=(1X25 )+(0X24)+(1X23)+(1X22)+(0X21)+(0X20)=32+0+8+4+0+0=(44)10 (dndn-1…d1d0)2 = (dnX2n )+ (dn-1X2n-1)+…+ (d1X21)+(d0X20) Where d = {0,1}

  4. A binary digit is called the BIT (BInary digiT). A group of eight bits is called the BYTE. The leftmost bit of a number is called the Most Significant Bit (MSB). The rightmost bit of a number is called the Least Significant Bit (LSB). A binary system with N bits can represent the numbers from 0 to 2N-1. In a binary system with N digits there are 2N different combinations. A binary number is multiplied by two, if we append a zero at the LSB. Prefixes in the binary system: 210 = 1,024 = 1K (Kilo) 220 = 1,024 X 1,024 = 1,048,576 = 1M (Mega) 230 = 1G (Giga) 240 = 1T (Tera) Powers of 2: 20 = 1 21 = 2 22 = 4 23 = 8 24 = 16 25 = 32 26 = 64 27 = 128 28 = 256 29 = 512 210=1024=1K 216 = 65536 The Binary Numbering System (Cont.)

  5. A General Numbering System With Base R • A numbering system with base R can have digits in the range from 0 to R-1 • A number in a system with base R is expressed by the following expression: Examples: • A computer that uses light (color) to represent information will use a numbering system with a base of 3, since there are three basic colors. • Usually in computers we group the bit of a number for simplicity. A group of 4 bits yields a system with 16 combinations. Such a system is called the Hexadecimal system (dndn-1…d1d0)R = (dnXRn )+ (dn-1XRn-1)+…+ (d1XR1)+(d0XR0) Where d = {0.. R-1}

  6. Conversion from a system with base R to Decimal • To convert a number from a system with base R to decimal we replace R with the base of the system in the following expression: Examples: • (214)5 = (2X52 )+(1X51)+(4X50) = (2X25)+(1X5)+(4X1)=50+5+4= (59)10 • (2021)3 = (2X33)+(0X32)+(2X31)+(1X30)=(2X27)+(2X3)+(1X1)=54+6+1= (61)10 • (13A)12 = (1X122)+(3X121)+(10X120)=144+36+10=(190)10 • (4C)18 = (4X181)+(12X180)=72+12=(84)10 • (135)4 = Invalid. Digit 5 is greater than 4 which is the base of the system. (dndn-1…d1d0)R = (dnXRn )+ (dn-1XRn-1)+…+ (d1XR1)+(d0XR0)

  7. Examples Do the following conversions: • (234)6 = (?)10 • (2012)3 = (?)10 • (A1C)14 = (?)10 • (5H)20 = (?)10 • (122)4 = (?)10 • (1220)4 = (?)10 • (12200)4 = (?)10 • (122003)4 = (?)10

  8. Conversion from Decimal to a system with base R A decimal number can be converted into its equivalent in base R using the following procedure: Step 1: Perform the integer division of the decimal number by R and record the remainder. e.g. if the number is 70 and the base is 4 then 70/4 = 17 + 2/4 Step 2: Replace the decimal number with the result of the division in step 1. Repeat step 1, until a zero result is found. e.g. 17/4 = 4 + 1/4 4/4 = 1 + 0/4 1/4 = 0 + 1/4 Step 3: The number is formed by reading the remainders in reversed order. e.g. (70)10 = (1012)4

  9. Examples Do the following conversions: • (53)10 = (?)2 • (47)10 = (?)3 • (124)10 = (?)14 • (253)10 = (?)20 • (97)10 = (?)7 • (25)10 = (?)4 • (250)10 = (?)4 • (100)10 = (?)4

  10. Homework: Do the necessary conversions to fill up the table below:

  11. Homework Do the following conversions: • (244)5 = (?)10 • (2132)4 = (?)10 • (A4F)18 = (?)10 • (6H)22 = (?)10 • (1202)3 = (?)10 • (12020)3 = (?)10 • (120200)3 = (?)10 • (1202003)4 = (?)10

  12. The Octal and Hexadecimal Numbering Systems • Computers use the binary system to represent data. In most cases a number is represented with 16, 32 or more bits, which is difficult to be handled by humans. • To make binary numbers easier to manipulate, we can group the bits of the number in groups of 2, 3 or 4 bits. • If we take a group of 2 bits, then we can have 4 combinations or different digits in each group. Thus the new system is a system with the base of 4. e.g. (10110100)2= (10 11 01 00)2= (2310)4 • The system with the base 4 is not widely used because many digits are still required to represent typical numbers. (11)2 = 3 (00)2 = 0 (10)2 = 2 (01)2 = 1

  13. The Octal and Hexadecimal Numbering Systems (Cont.) • If we take a group of 3 bits, then we can have 8 combinations or different digits in each group. Thus the new system is a system with the base of 8 and is called the Octal system. e.g. (10110100)2= (10 110 100)2= (264)8 • If we take a group of 4 bits, then we can have 16 combinations or different digits in each group. Thus the new system is a system with the base of 16and is called the hexadecimal or hex system. Letters A to F are used to represent digits from 10 to 15. e.g. (10110100)2= (1011 0100)2= (B4)16 (110)2 = 6 (010)2 = 2 (100)2 = 4 (1011)2 =11=B (0100)2 = 4

  14. Decimal, Binary, Octal and Hexadecimal Conversion Table Decimal Binary Base 4 Octal Hex 0 0000 0 0 0 1 0001 1 1 1 2 0010 2 2 2 3 0011 3 3 3 4 0100 10 4 4 5 0101 11 5 5 6 0110 12 6 6 7 0111 13 7 7 8 1000 20 10 8 9 1001 21 11 9 10 1010 22 12 A 11 1011 23 13 B 12 1100 30 14 C 13 1101 31 15 D 14 1110 32 16 E 15 1111 33 17 F

  15. Examples

  16. Homework Do the following conversions: • (53)10 = (?)2 = (?)4 = (?)8 = (?)16 • (1000111)2 = (?)10 = (?)4 = (?)8 = (?)16 • (1203)4 = (?)10 = (?)2 = (?)8 = (?)16 • (253)8 = (?)10 = (?)2 = (?)4 = (?)16 • (9C)16 = (?)2 = (?)4 = (?)8 = (?)10

  17. Fractional number representation • Let us assume a radix point (.) with the decimal part on the left and the fractional part on the right • Then • Example:

  18. Examples (2B.1A)

  19. Converting fractional numbers from decimal number system to radix r • To convert a decimal fraction to a radix r number, repeatedly multiplythe fraction part by r and retain the integer digit in sequence until the fraction is zero, or the number of digits required are obtained (the number of digits may be infinite). • Then the digits following theradix point from left to right with the integer digits, the earliest obtained first.

  20. Example • 0.5625  2 = 1.1250 Most significant • 0.1250  2 = 0.2500 • 0.2500  2 = 0.5000 • 0.5000  2 = 1.0000 Least significant

  21. Converting fractional numbers from from binary to hex and from hex to binary • The same principle with integer numbers applies: Group four bits together, padding with zeros if necessary, but this time from left to right, and convert its 4-bit group to its corresponding Hexadecimal number and vice versa • Examples:

  22. Homework

  23. The Binary Coded Decimal (BCD) System 4 =(0100)2 • In many applications it is required to encode each decimal digit to the equivalent 4-bit binary number. This binary code is called the BCD code. e.g. (2 4 9)10= (0010 0100 1001)BCD Examples: • (173)10 = (?)2 = (?)BCD • (1000 0111)BCD = (?)10 • (0100 0010)2 = (?)BCD • (53)16 = (?)BCD • (1011 0101)BCD = (?)10 2 =(0010)2 9 = (1001)2

  24. Addition in any numbering system • Addition in any numbering system can be performed by following the same rules used for decimal addition, where 10 is replaced by the base of the system (R). • Decimal Addition: 7 4 3 1 8 6 + 9 2 9 • Rules for addition in the decimal system: • Begin the addition by adding the 2 least significant digits first. • Perform the integer division of the sum with 10. Write down the remainder of the division and carry out the result to the next column. • Repeat the addition for the next columns by adding the two digits and the carry from the previous column. 3 + 6 = 9  9/10 = 0 + 9/10  write 9 and carry 0 8 + 4 = 12  12/10 = 1 + 2/10  write 2 and carry 1 1+ 7 + 1 = 9  9/10 = 0 + 9/10  write 9 and carry 0

  25. Addition in any numbering system • Rules for addition in a system with base R: • Begin the addition by adding the 2 least significant digits first. • Perform the integer division of the sum with R. Write down the remainder of the division and carry out the result to the next column. • Repeat the addition for the next columns by adding the two digits and the carry from the previous column. Examples: Perform the following additions • (173)8+ (265)8 = (?)8 • (01101011)2+ (00111010)2 = (?)2 • (1243)5+ (234)5 = (?)5 • (1A79)16+ (C827)16 = (?)16 • (1A79)18+ (C827)18 = (?)18

  26. Subtraction in any numbering system • Subtraction in any numbering system can be performed by following the same rules used for decimal addition, where 10 is replaced by the base of the system (R). • Decimal Subtraction: 7 4 9 1 8 6 - 5 6 3 • Rules for subtraction in the decimal system: • Begin the subtraction from 2 least significant digits first. • If the minuend is greater than the subtrahend then perform the subtraction. • If the minuend is less than the subtrahend then borrow 1 from the next column. Write down the result of (minuend + 10 - subtrahend). The one borrowed must be subtracted from the minuend of the next column. • Repeat the subtraction for the next columns. (96)  9 - 6 = 3  write 3 and borrow 0 from next column (4<8)  borrow 1  10+4-8=6  write 6 and borrow 1 from next column (7-11) 7 - 1 - 1 = 5 write 5 and borrow 0 from next column

  27. Subtraction in any numbering system • Rules for subtraction in a system with base R: The rules for subtraction in a system with base R are the same as in decimal, except that a borrow into a given column adds R units to the minuend digit. Examples: Perform the following subtractions: • (476)10 - (285)10 = (?)10 • (285)10 - (476)10 = (?)10 • (173)8 - (265)8 = (?)8 • (01101001)2- (00111010)2 = (?)2 • (423)5 - (234)5 = (?)5 • (61A9)16- (C827)16 = (?)16 • (61A9)18- (C827)18 = (?)18

  28. Subtraction using the complement’s method • In the previous examples, the subtraction {(285)10 - (476)10 } give a result equal to 809. The correct result is -191. If we examine carefully the subtraction we can observe that the subtraction of the last digit was carried out using a borrow, i.e. the result 809 is obtained after we borrow 1000. If we add 809 and 191 then we get 1000, which is what is borrowed in order to complete the subtraction. The number 809 is said to be the 10’s complement of the number 191. This shows that: • Negative numbers can be represented in the complement’s form. • Subtraction in the decimal system, can be carried out by adding to the minuend the 10’ s complement of the subtrahend. i.e. (285)10 - (476)10 = (285)10 + (-476)10 = (285)10 + [ (523)9’s ++ 1] = (285)10’s + (524)10’s = (809)10’s • Subtraction in a system with base R, can be carried out by adding to the minuend the R’ s complement of the subtrahend.

  29. Examples on subtraction using the complement’s method Perform the following subtractions using the R’s complement method: • (476)10 - (285)10 = (?)10 • (285)10 - (476)10 = (?)10 • (173)8 - (265)8 = (?)8 • (01101001)2- (00111010)2 = (?)2 • (423)5 - (234)5 = (?)5 • (61A9)16- (C827)16 = (?)16 • (61A9)18- (C827)18 = (?)18

  30. Homework: Do the necessary operations to fill up the table below:

  31. Negative Number Representation: Signed Magnitude • In the Signed Magnitude representation the most significant bit is used as the sign of the number. The sign bit is zero for positive numbers and one for negative numbers. • SM:8 means Signed Magnitude with 8 bits (1 for the sign and 7 for the magnitude. • The problem with the SM is that there are two values for zero: (0000000 = +0, and 10000000 = -0).

  32. Negative Number Representation: One’s Complement • The Ones Complement representation can be derived from the Signed Magnitude representation. If the number is positive then the one’s complement is the same as the SM. If the number is negative then the one’s complement is obtained by inverting all magnitude bits of the SM. The sign bit is unchanged. • The problem with the One’s Complement is that there are two values for zero: (0000000 = +0, and 11111111 = -0).

  33. Negative Number Representation: Two’s Complement • If the number is positive then the two’s complement is the same as the SM. If the number is negative then the two’s complement is obtained by adding 1to the magnitude bits of the one’s complement. The sign bit is unchanged. • The two’s complement is widely used in computers to represent signed integers. In most languages such as Pascal and C an integer variable is represented in a 16-bit two’s complement representation.

  34. Negative Number Representation: Excess 2N-1 • The Excess 2N-1 of a number is obtained by adding 2N-1 to the number and then convert it to binary. Where N is the number of bits used to represent the number. For example if 8 bits are used then 2N-1 is 27 = 128 and the system is called the Excess 128 system. • Examples: (+38)10 = 128 + 38 = 166 = (10100110)ex-128 (-38)10 = 128 - 38 = 90 = (01011010)ex-128 (10101011) ex-128 = 171 = 128 + 43 = (+43)10 (01010101) ex-128 = 85 = 128 -43 = (-43)10 • Note that the 2N-1 can also be obtained by inverting the sign bit of the two’s complement of the number.

  35. Negative Number Representation: Excess (2N-1-1) • The Excess (2N-1 -1)of a number is obtained by adding (2N-1 -1)to the number and then convert it to binary. Where N is the number of bits used to represent the number. For example if 8 bits are used then (2N-1 -1) is (27 -1)= 127 and the system is called the Excess 127 system. • Examples: (+38)10 = 127 + 38 = 165 = (10100101)ex-127 (-38)10 = 127 - 38 = 89 = (01011001)ex-127 (10101011) ex-128 = 171 = 128 + 43 = (+43)10 (01010101) ex-128 = 85 = 128 -43 = (-43)10 • Note that the (2N-1 -1) can be obtained by inverting the sign bit of the one’s complement of the number, ONLY if the number is positive. • The (2N-1 -1) representation is used in computers to represent the exponent of floating point numbers.

  36. Negative Number Representation: 16’s Complement • Examples: (+38)10 = 127 + 38 = 165 = (10100101)ex-127 (-38)10 = 127 - 38 = 89 = (01011001)ex-127 (10101011) ex-128 = 171 = 128 + 43 = (+43)10 (01010101) ex-128 = 85 = 128 -43 = (-43)10 • The (2N-1 -1) representation is used in computers to represent the exponent of floating point numbers.

  37. Examples • Fill up the table shown below:

  38. Homework • Fill up the table shown below:

More Related