71
ICS124 Session 2 Data Representation 1

ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Embed Size (px)

Citation preview

Page 1: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

ICS124

Session 2

Data Representation

1

Page 2: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Review QUIZ

1) Additional data and programs not being used by the processor are stored in:a) secondary storage c) input unitsb) output units d) the CPU

2) The entire computer system is coordinated by:a) the ALU c) registersb) the control unit d) arithmetic operators

3) The control unit operates in:a) E-time c) machine timeb) I-time d) ALU time

4) "Mark sensing" is another term for:a) MICR c) OMRb) POS d) OCR

5) Another name for secondary storage is:a) cylinder storage c) auxiliary storageb) density d) memory

2

Page 3: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Review QUIZ

1) Additional data and programs not being used by the processor are stored in:a) secondary storage c) input unitsb) output units d) the CPU

2) The entire computer system is coordinated by:a) the ALU c) registersb) the control unit d) arithmetic operators

3) The control unit operates in:a) E-time c) machine timeb) I-time d) ALU time

4) "Mark sensing" is another term for:a) MICR c) OMRb) POS d) OCR

5) Another name for secondary storage is:a) cylinder storage c) auxiliary storageb) density d) memory

3

Page 4: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Objectives:By the end of this session, the student will be able to:Define a Positionally Dependent numbering systemGive examples of positionally dependent and positionally independent numbering systemsList the digits used in the binary, octal and hexadecimal numbering systemExpress each position of significance as the base to an appropriate exponentList the steps to convert a decimal number to any numbering systemUse the technique to perform conversions of decimal numbers to binary, octal and hexadecimal numbering systemsExplain the process of converting from any numbering system to the decimal number systemUse the process to perform conversions of binary, octal or hexadecimal numbering systems to the decimal numbering systemList the steps of the short-cut to convert a binary number to an octal numberUse the technique to perform binary to octal conversionsList the steps of the short-cut to convert a binary number to a hexadecimal numberUse the technique to perform binary to hexadecimal conversionsList the steps of the short-cut to convert an octal number to a binary numberUse the technique to perform octal to binary conversionsList the steps of the short-cut to convert a hexadecimal number to a binary numberUse the technique to perform hexadecimal to binary conversionsDefine the terms: bits, bytes, nibbles and wordsExplain why computers use the binary numbering system

4

Page 5: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems

BackgroundNumbering systems have been around since the concept of quantity was developed. With the advent of writing, numbering systems have been recorded starting with the Babylonian numbering system around 3100BC:

http://www.phys.virginia.edu/classes/109N/lectures/babylon.html1996 Michael Fowler

5

Page 6: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Background, continuedThe Roman numbering system is still used today, but not as a functional system. The numbering system widely used today is the Arabic numbering system:

Arabic Roman1 I2 II3 III4 IV5 V6 VI7 VII8 VIII9 IX10 X50 L100 C500 D1000 M

6

Page 7: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Decimal numbering systemThe Arabic numbering system is a Decimal numbering system. There are three attributes we will look at:

The digits of this numbering system are positionally dependent. It is based on a quantity of 10. Contains the digits: 0 1 2 3 4 5 6 7 8 9

Positionally dependentPositionally dependent means that the significance of a digit is related to where it can be found in the number. For example, does the digit '1' mean the same thing in these two numbers?

51163

These are the same numbers in Roman numerals, does the different position of the 'L' character change its significance?

LICLXIII

7

Page 8: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Positionally dependent, continuedA closer look at the composition of a decimal number:

1492

Is composed of 1000 + 400 + 90 + 2.

Another way of expressing this is:1492 = (1 x 1000) + (4 x 100) + (9 x 10) + (2 x 1)

If we take the multipliers (1000, 100, 10, 1) and express them as exponents of the base:

1000 = 103 (10 x 10 x 10 - ten multiplied by itself 3 times)100 = 10 x 10 = 102 (10 x 10 - ten multiplied by itself 2 times)10 = 101

1 = 100

1492 = (1 x 103) + (4 x 102) + (9 x 101) + (2 x 100)

8

Page 9: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Positionally dependent, continuedIn summary, we can say that a digit's significance is dependent on its position within the number.

The more digits that sit to a digits right, the more significant the digit:88888

In the above number the '8' that is the rightmost digit has less significance than the '8' digit that is leftmost.

Terms such as 'Least Significant Digit' (LSD), and 'Most Significant Digit' (MSD)

are used to describe this property.

As more significant digits are added, the exponent is increased by one.

... 106 105 104 103 102 101 100

9

Page 10: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 10The base of the exponents gives the numbering system its name. So the decimal numbering system is also referred to as base-10.

The digits of the decimal numbering system cycle on every tenth digit. Once all of the digits have been exhausted, the next highest position of significance is updated by one. Starting at zero, to exhaust all possible digits, the order would be:

012345678

9

10

Page 11: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 10, continuedTo increment by 1, the next highest position of significance is updated, and the cycle repeats:

0 101 112 123 134 145 156 167 178 189 19

11

Page 12: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 10, continuedBy convention, the '0' that became a '1' in the left column is not written, otherwise we would see:

00 1001 1102 1203 1304 1405 1506 1607 1708 1809 19

As there are an infinite number of positions of significance, it is actually impossible to write all the leading zeroes for numbers.

12

Page 13: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 10, continuedA list of decimal numbers (leading zeroes added):

000 017 034 051 068 085 102 119 136 153001 018 035 052 069 086 103 120 137 154002 019 036 053 070 087 104 121 138 155003 020 037 054 071 088 105 122 139 156004 021 038 055 072 089 106 123 140 157005 022 039 056 073 090 107 124 141 158006 023 040 057 074 091 108 125 142 159007 024 041 058 075 092 109 126 143 160008 025 042 059 076 093 110 127 144 161009 026 043 060 077 094 111 128 145 162010 027 044 061 078 095 112 129 146 163011 028 045 062 079 096 113 130 147 164012 029 046 063 080 097 114 131 148 165013 030 047 064 081 098 115 132 149 166014 031 048 065 082 099 116 133 150 167015 032 049 066 083 100 117 134 151 168

016 033 050 067 084 101 118 135 152.... 13

Page 14: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

General statementsSome general statements about positionally dependent numbering systems, using the Base-10 numbering system as an example:

There are base digits in the system (base is 10, therefore there are 10 digits)The digits in the numbering system start at 0 and go to base - 1 (base is 10, therefore base - 1 is 9. Therefore, the digits go from 0 to 9)The digits of significance, starting at the right, and moving left are:

expressed as an exponent where the base is the base of the numbering system- which is how the term 'base' comes to be

the exponents start at 0 and increment by 1 for each digit of significance

14

Page 15: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

General statementsSome general statements about positionally dependent numbering systems:

There are base digits in the systemThe digits in the numbering system start at 0 and go to base - 1The digits of significance, starting at the right, and moving left are:

expressed as an exponent where the base is the base of the numbering system- which is how the term 'base' comes to be

the exponents start at 0 and increment by 1 for each digit of significance

What would the binary (base-2) numbering system look like?

15

Page 16: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Binary numbering systemThe binary numbering system has three attributes that we will look at:

The digits of this numbering system are positionally dependent. It is based on a quantity of 2. Contains the digits: 0 1

Positionally dependentThe definition remains the same as in the decimal numbering system. However, lets take a closer look at the composition of a binary number.

1101 (this number is not one thousand one hundred and one)

Looking back at the base-10 numbering system, as more significant digits were added, the exponent of the base increased by one.

Using this a model, then the significance of the digits within the binary numbering system would be:

... 26 25 24 23 22 21 20

16

Page 17: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Positionally dependent, continuedThe number 1101 could be expressed as:

(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20)

There are differences when referring to binary digits, they are called bits.

Also, the terms for significance are:Least Significant Bit (LSB), andMost Significant Bit (MSB)

17

Page 18: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 2The base of the exponents gives the numbering system its name. So the binary numbering system is also referred to as base-2.

The digits of the binary numbering system cycle on every second bit. Once all of the bits have been exhausted, the next highest position of significance is updated by one. Starting at zero, to exhaust all possible bits, the order would be:01

A list of binary numbers (leading zeroes added):00000 01000 10000 1100000001 01001 10001 1100100010 01010 10010 1101000011 01011 10011 1101100100 01100 10100 1110000101 01101 10101 1110100110 01110 10110 1111000111 01111 10111 11111

....18

Page 19: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

General statementsSome general statements about positionally dependent numbering systems:

There are base digits in the systemThe digits in the numbering system start at 0 and go to base - 1The digits of significance, starting at the right, and moving left are:

expressed as an exponent where the base is the base of the numbering system- which is how the term 'base' comes to be

the exponents start at 0 and increment by 1 for each digit of significance

What would the octal (base-8) numbering system look like?

19

Page 20: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Octal numbering systemThe octal numbering system has three attributes that we will look at:

The digits of this numbering system are positionally dependent. It is based on a quantity of 8. Contains the digits: 0 1 2 3 4 5 6 7

Positionally dependentThe definition remains the same as in the decimal numbering system. However, lets take a closer look at the composition of an octal number.

571

Looking back at the base-10 numbering system, as more significant digits were added, the exponent of the base increased by one.

Using this a model, then the significance of the digits within the octal numbering system would be:

... 86 85 84 83 82 81 80

20

Page 21: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Positionally dependent, continuedThe number 571 could be expressed as:

(5 x 82) + (7 x 81) + (1 x 80)

21

Page 22: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 8The base of the exponents gives the numbering system its name. So the octal numbering system is also referred to as base-8.

The digits of the octal numbering system cycle on every eighth digit. Once all of the digits have been exhausted, the next highest position of significance is updated by one. Starting at zero, to exhaust all possible digits, the order would be:

01234567

22

Page 23: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 8, continuedA list of octal numbers (leading zeroes added):

000 021001 022002 023003 024004 025005 026006 027007 030010 031011 032012 033013 034014 035015 036016 037017 040020 041

....23

Page 24: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

OctalAdd 1 to each of the octal numbers below:

1 + 1 =

27 + 1 =

23 + 1 =

177 + 1 =

16 + 1 =

77 + 1 =

24

Page 25: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Octal, continuedAdd 1 to each of the octal numbers below:

1 + 1 = 2

27 + 1 = 30

23 + 1 = 24

177 + 1 = 200

16 + 1 = 17

77 + 1 = 100

25

Page 26: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

General statementsSome general statements about positionally dependent numbering systems:

There are base digits in the systemThe digits in the numbering system start at 0 and go to base - 1The digits of significance, starting at the right, and moving left are:

expressed as an exponent where the base is the base of the numbering system- which is how the term 'base' comes to be

the exponents start at 0 and increment by 1 for each digit of significance

What would the hexadecimal (base-16) numbering system look like?

26

Page 27: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Hexadecimal numbering systemThe hexadecimal numbering system has three attributes that we will look at:

The digits of this numbering system are positionally dependent. It is based on a quantity of 16. Contains the digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F

Positionally dependentThe definition remains the same as in the decimal numbering system. However, lets take a closer look at the composition of a hexadecimal number.

1492

Looking back at the base-10 numbering system, as more significant digits were added, the exponent of the base increased by one.

Using this a model, then the significance of the digits within the hexadecimal numbering system would be:... 166 165 164 163 162 161 160

27

Page 28: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Positionally dependent, continuedThe number 1492 could be expressed as:

(1 x 163) + (4 x 162) + (9 x 161) + (2 x 160)

28

Page 29: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 16The base of the exponents gives the numbering system its name. So the hexadecimal numbering system is also referred to as base-16.

The digits of the hexadecimal numbering system cycle on every sixteenth digit. Once all of the digits have been exhausted, the next highest position of significance is updated by one.

The three numbering systems we have looked at use the Arabic numerals to represent the digits. The hexadecimal numbering system has more digits than can be accommodated using the Arabic symbols. The solution is to use alphabetic letters to represent the digits beyond 9.

29

Page 30: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 16, continuedStarting at zero, to exhaust all possible digits, the order would be:

0123456789ABCDEF

30

Page 31: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

Based on 16, continuedA list of hexadecimal numbers (leading zeroes added):

000 010001 011002 012003 013004 014005 015006 016007 017008 018009 01900A 01A00B 01B00C 01C00D 01D00E 01E00F 01F

....

31

Page 32: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

HexadecimalAdd 1 to each of the hexadecimal numbers below:

1 + 1 =

9 + 1 =

E + 1 =

45 + 1 =

F + 1 =

C5B + 1 =

1F + 1 =

2FF + 1 =

32

Page 33: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Numbering Systems, Continued

HexadecimalAdd 1 to each of the hexadecimal numbers below:

1 + 1 = 2

9 + 1 = A

E + 1 = F

45 + 1 = 46

F + 1 = 10

C5B + 1 = C5C

1F + 1 = 20

2FF + 1 = 300

33

Page 34: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases

34

Page 35: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases

Converting between numbering systemsMost people are comfortable dealing with a specific numbering system, such as decimal. To work with numbers in another numbering system, such as hexadecimal, it is often preferable to convert the hexadecimal number to decimal in order to perform the work (for example, multiplying two hexadecimal numbers together).

In some cases conversions between binary and octal or hexadecimal is required. It is inconvenient to convert first to decimal, then to the new base, so some short cuts exist.

35

Page 36: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Writing conventionWhat is the value of the following number?

10

36

Page 37: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Writing conventionWhat is the value of the following number?

10

is it

(1 x 21) + (0 x 20)or

(1 x 101) + (0 x 100) or

(1 x 81) + (0x80)or

(1 x 161) + (0 x 160)

37

Page 38: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Writing convention, continuedTo prevent confusion, the base of the number is subscripted after the number, so we know that

1016

is

1010

is

108 is

102

is

38

Page 39: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting between basesHere are the first 20

10 numbers of each of the 4 numbering systems discussed:

Decimal Binary Octal Hexadecimal0 0 0 01 1 1 12 10 2 23 11 3 34 100 4 45 101 5 56 110 6 67 111 7 78 1000 10 89 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F16 10000 20 1017 10001 21 1118 10010 22 1219 10011 23 13

39

Page 40: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting between basesYou could create a table of the four numbering systems from 0 to infinity to perform conversions, or you could learn some basic techniques that can be applied to perform the conversions.

40

Page 41: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Whole Number DivisionRemember the terminology used in whole number division:

a / b = c R da is called the dividendb is called the divisorc is called the quotientd is called the remainder

e.g. 7 / 2 = 3 R 1

7 is the dividend2 is the divisor3 is the quotient1 is the remainder

41

Page 42: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimalThe process is the same for any base when converting from decimal. The digits created will begin at the least significant digit and work its way to the left (to the most significant digit).

1) divide the decimal number by the base, getting quotient and remainder

2) the remainder is the digit in the new numbering system (written to the left of the previous number)

3) take the quotient as a decimal number and repeat from step 1, until the quotient is 0

42

Page 43: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 1492

10 to base 10 (this will show the process):

1492 / 10 = 149 R2

149 / 10 = 14 R9

14 / 10 = 1 R 4

1 / 10 = 0 R 1

1 4 9 210

43

Page 44: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 13

10 to base 2:

??

44

Page 45: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 13

10 to base 2:

13 / 2 = 6 R 16 / 2 = 3 R 03 / 2 = 1 R 11 / 2 = 0 R 1

1310

= 11012

45

Page 46: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 1084

10 to base 16:

Remember that hexadecimal has alphabetic letters to represent values between 10

10 and 15

10:

A16

= 1010

B16

= 1110

C16

= 1210

D16

= 1310

E16

= 1410

F16

= 1510

1084 / 16 = 67 R 12 (1210

= C16

)67 / 16 = 4 R 34 / 16 = 0 R 4

108410

= 43C16

46

Page 47: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 167

10 to base 8:

?

47

Page 48: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedConvert 167

10 to base 8:

167 / 8 = 20 R 720 / 8 = 2 R 42 / 8 = 0 R 2

16710

= 2478

48

Page 49: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedPerform the following conversions:

Base-10 Base-2 Base-8 Base-16155

3434

473

2562

190

2989

49

Page 50: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from decimal, continuedPerform the following conversions:

Base-10 Base-2 Base-8 Base-16155 10011011 233 9B

3434 110101101010 6552 D6A

473 111011001 731 1D9

2562 101000000010 5002 A02

190 10111110 276 BE

2989 101110101101 5655 BAD

50

Page 51: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimalThe process is the same for any base when converting to decimal, and is easier than converting from decimal to a base.

If 'b' is the base (ie. 2, 8, 16), 'd' is the digit, and 'e' is the exponent of the base, then the formula:

n

debe

e=0

will perform the conversion.

This means:

dnbn + . . . + d

3b3 + d

2b2 + d

1b1 + d

0b0

51

Page 52: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continued

n

debe ==> d

nbn + . . . + d

3b3 + d

2b2 + d

1b1 + d

0b0

e=0

Assuming base-2, and the bits: 10110112, then

1x26 + 0x25 + 1x24 + 1x23 + 0x22 + 1x21 + 1x20

= (1 x 64) + (0 x 32) + (1 x 16) + (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1)

= 64 + 16 + 8 + 2 + 1

= 9110

52

Page 53: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continued

n

debe ==> d

nbn + . . . + d

3b3 + d

2b2 + d

1b1 + d

0b0

e=0

Assuming base-16, and the digits: C0FFEE16

, then

Cx165 + 0x164 + Fx163 + Fx162 + Ex161 + Ex160

= (12 x 1,048,576) + (0 x 65,536) + (15 x 4,096) + (15 x 256) + (14 x 16) + (14 x 1)

= 12,582,912 + 0 + 61,440 + 3,840 + 224 + 14

= 12,648,43010

53

Page 54: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continued

n

debe ==> d

nbn + . . . + d

3b3 + d

2b2 + d

1b1 + d

0b0

e=0

Assuming base-8, and the digits: 6548, then

?

54

Page 55: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continued

n

debe ==> d

nbn + . . . + d

3b3 + d

2b2 + d

1b1 + d

0b0

e=0

Assuming base-8, and the digits: 6548, then

6x82 + 5x81 + 4x80

= (6 x 64) + (5 x 8) + (4 x 1)

= 384 + 40 + 4

= 42810

55

Page 56: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continuedConvert the following to decimal:

DEED16

3218

100101102

56

Page 57: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting to decimal, continuedConvert the following to decimal:

DEED16

= 5706910

3218

= 20910

100101102

= 15010

57

Page 58: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Converting from binaryThere are many occurrences when you will convert from binary to a base other than 10, or vice versa. There are short-cuts for these conversions.

Binary to octalTo convert from binary to octal:

1) Start at the least significant bit, and place the bits into groups of three bits

2) Convert each of these groups (independent of each other) into octal digits

For example, convert 10100111112 to octal:

1-010-011-111

= 12378

58

Page 59: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Binary to hexadecimalTo convert from binary to hexadecimal:

1) Start at the least significant bit, and place the bits into groups of four bits

2) Convert each of these groups (independent of each other) into hexadecimal digits

For example, convert 10100111112 to hexadecimal:

10-1001-1111

= 29F16

59

Page 60: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Octal to binaryTo convert from octal to binary, the reverse process is applied. Convert each octal digit into groups of three bits:

For example, convert 32158 to binary:

011-010-001-101

= 110100011012

60

Page 61: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

Hexadecimal to binaryTo convert from hexadecimal to binary, the reverse process is applied. Convert each hexadecimal digit into groups of four bits:

For example, convert 10AD16

to binary:

0001-0000-1010-1101

= 10000101011012

61

Page 62: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

PracticeConvert the following numbers to the requested base. Use the shortcuts from the lecture:

FEED16

to base-2

10101110110010110112 to base-16

1111011011000112 to base-8

D0CA16

to base-8

62

Page 63: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

PracticeConvert the following numbers to the requested base. Apply shortcuts if appropriate:

FEED16

to base-2 = 11111110111011012

10101110110010110112 to base-16 = 5765B

16

1111011011000112 to base-8 = 75543

8

D0CA16

to base-8 = 11010000110010102 = 150312

8

63

Page 64: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Converting between bases, continued

SummaryThe following chart summarizes the techniques to use based on the conversion desired:

From/To Binary Octal Decimal HexadecimalBinary Shortcut-3bit Repeated Addition Shortcut-4bitOctal Shortcut- 3bit Repeated Addition 2xShortcut with BinaryDecimal Repeated division Repeated Division Repeated divisionHexadecimal Shortcut- 4bit 2xShortcut with Binary Repeated Addition

64

Page 65: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers

65

Page 66: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers

Why computers use binaryThe previous slides regarding various numbering systems have relevance to computers.

What is it about a numbering system with two digits that makes it ideal for computers?

An electrical switch can have two states, either is on, or its off. A computer, being electrical, uses electrical switches to store data.

66

Page 67: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers

Why computers use binary, continuedA switch that is turned on can represent the bit '1', and a switch that is turned off can represent the bit '0'.

OFF ON ON OFF ON0 1 1 0 1

RAM and ROM memory are massive arrays of these switches. A 32MB RAM chip would contain over 268 million of these switches.

67

Page 68: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers, continued

Bits, Bytes, Nibbles and WordsWe have defined a bit as a single binary digit, that is either a '0' or a '1'. There are other terms used when dealing with binary numbers that is based on the number of bits in the number. These terms are:

Bytes Nibbles Words

BytesIn computers we look at bits in groups of eight. Early computers could not hold binary number that contained more than eight digits (bits). A group of eight bits is referred to as a byte.

Remember the aggregate terms for memory? KB, MB and GB? The 'B' represented bytes (8 bits). Sometimes you will see Kb or Mb. This is an aggregate of bits. Be wary of this and perform conversions as required.

That is why on the previous slide I said 32MB RAM would contain over 268 million bits (switches).

68

Page 69: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers, continued

NibblesWhen performing conversions to hexadecimal, the bits are grouped four at a time.

So when we talk about groups of 4 bits we refer to a nibble.

WordsWords are not a fixed size relative to bits. A word is related to the processor in the computer system.

Inside the CPU, there are registers under the direction of the Control Unit. The number of bits that make up these registers defines the word size of a CPU. Another register that define word size is the ALU.

CPU Numeric range Processor8-bit 0 - 255 8088 / 808616-bit 0 - 65,535 8028632-bit 0 - 4,294,967,295 i386...Pentium464-bit 0 - 1.844674407x1019 Itanium, Sparc (Sun), Power3-II (IBM)

69

Page 70: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers, continued

Summary of termsWhat we have is:

1 bit4 bits = 1 nibble8 bits = 2 nibbles = 1 byte

70

Page 71: ICS124 Session 2 Data Representation 1. Review QUIZ 1) Additional data and programs not being used by the processor are stored in: a) secondary storagec)

Binary and computers, continued

Role of Octal and HexadecimalThe octal and hexadecimal systems are used in computer systems to work with bits in more manageable chunks.

Instead of looking a string of bits such as 0101011101102, and 010101100110

2, it is

easier to work with 57616

and 56616

or 25668 and 2546

8.

Octal is used far less than hexadecimal, however, in UNIX being able to work with octal numbers is necessary when setting up file permissions.

71