39
1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

Embed Size (px)

Citation preview

Page 1: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

1

Introduction to Information Technology

BINARY REPRESENTATION OF REAL NUMBERS AND TEXTHEXADECIMAL AND OCTAL

Lecture Notes - 2

Page 2: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

2

Topics

Representing “Real Numbers” in Binary

Representing Negative Numbers in Binary

Representing Text in Binary

Determining How Many Bits are Needed to Represent Something

Octal and Hexadecimal Numbering Systems

Page 3: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

3

Representing Real Numbers in Bits

We’ve learned how to represent integers in binary form. Real numbers can also be represented in binary. We will illustrate this using thermometer measurements as an

example. A mercury thermometer reflects temperature that can

continuously vary over its range of measurement (an analog device).

A digital thermometer would require an infinite number of bits to accomplish the same thing.

If we are building a digital thermometer, we must make some choices and determine some parameters:

Precision (number of bits we will use) v. cost Accuracy (how true is our measurement against a given

standard).

Page 4: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

4

CONTINUOUS VS. DISCRETE FUNCTIONS

Recall that mercury thermometer measurements are a continuous function: there is an infinite number of points making up that function. Discrete functions have a finite number of values.

Page 5: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

5

FUNCTIONS In mathematics, a function is an association between two sets of

values in which each element of one set has one assigned element in the other set so that any element selected becomes the independent variable and its associated element is the dependent variable. Thus, in:

y = f(x)

y is said to be a function of x.

Common functions we might deal with: Functions of Time Functions of Space Functions of Frequency Functions of Power

Usually, functions are represented as a relationship on an x-y axis graph.

Page 6: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

6

THE SINE WAVE IS A FUNCTION

Page 7: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

7

REPRESENTING REAL NUMBERS

What is the range we wish to measure? How many values do we need to provide adequate precision? How many bits are we willing to allocate? Suppose we want to represent a range of temperature

measurements between 60-70oF There is an infinite number of possible different temperature

readings between 60-70oF Let’s decide that 256 different temperature values between

60-70 would give us more than enough precision. An 8-bit code would provide these values. Why 8 bits?

Using temperature values as an example:

70-60256

= 0.039oF

The 256 temperatures we can represent are separated by .039

Page 8: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

8

CONVERTING TEMPERATURE INTO BITS

We can use the 8-bit word to encode the following values:

Binary Codeword Temperature, oF00000000 60.0000000000100000001 60.03960.0390000001000000010 60.07860.0780000001100000011 60.11760.117

.. ..

.. ..1111110111111101 69.88369.8831111111011111110 69.92269.9221111111111111111 69.96169.961

Page 9: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

9

ANOTHER TEMPERATURE EXAMPLE

Suppose we want to read the thermometer to the hundredth of a degree between the values of -40 and +140oF.

How many bits are required? 180 x 100 = 18000 steps Can implement with a 15 bit code (215 = 32768) Note “wasted” bits

Precision now: to the hundredth degree Is a precise instrument the same as an accurate one?

How do we build the code now?

Page 10: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

10

THERMOMETER CODING - ONE METHOD

140.00º F 100011001010000139.99º F 100011001001111139.98º F 100011001001110139.97º F 1000110010011010.00º F 000111110100000

-39.98º F 000000000000010-39.99º F 000000000000001-40.00º F 000000000000000

Page 11: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

11

THERMOMETER CODING (ANOTHER METHOD)

0.04º F 0000000000001000.03º F 0000000000000110.02º F 0000000000000100.01º F 0000000000000010.00º F 000000000000000-0.01º F 111111111111111-0.02º F 111111111111110-0.03º F 111111111111101

Page 12: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

12

WHAT WAS THAT?

The most common way to represent negative number is using “2’s Complement Notation.”

Take the positive binary representation with the MSB as a sign bit (a 0 makes the representation positive)

01001 (+910) Take the binary complement (flip the bit values)

10110 Add a binary 1

10110 + 1 = 10111 (-910)

Page 13: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

13

2’S COMPLEMENT NOTATION

Express the decimal number -5 in 5-bit binary notation.

First determine the 5-bit binary representation of 5: 00101

Then complement (change 1s to 0s and 0s to 1s) each bit: 11010

Finally, add 1: 11011

-5 = 11011 in 2’s complement notation-5 = 11011 in 2’s complement notation(To reverse the process take the complement and add (To reverse the process take the complement and add 1!)1!)

Note that the 2’s complement of a 2’s complement of a Note that the 2’s complement of a 2’s complement of a number equals the original number.number equals the original number.

Page 14: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

14

IN-CLASS PROBLEMS

Page 15: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

15

How Can Alphanumeric Symbols be Represented in Binary Code?

How does the computer determine that “Hi” should be translated into 10010001101001? It uses a code, ASCII, which specifies by agreed upon convention, a unique 7 or 8 bit combination for each alphanumeric character.

American Standard Code for Information InterchangeAmerican Standard Code for Information Interchange

Information is entered via a keyboard.

For example “Hi”

The computer translates each typed character into a 7 (or 8) bit binary code.

For example, 10010001101001

Page 16: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

16

About ASCII

ASCII is a fixed length code, meaning it uses the same number of bits to represent all possible symbols produced by the source.

ASCII can represent 128 symbols (27 symbols) and Extended ASCII can represent 256 symbols (28 symbols).

Computer memories are usually structured in 8-bit units (bytes). It is convenient to represent alphanumeric symbols with a single

byte for storing text, so ASCII usually uses 7 bits plus an “extended” bit.” This is called “Extended ASCII.”

Appendix A in the text contains an ASCII key, which specifies a decimal, hexadecimal, and binary code for each alphanumeric character.

Using the ASCII key, how would we translate IT 101 into decimal or binary code?

Let’s look at the ASCII key….

Page 17: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

17

Sample ASCII Chart

Page 18: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

18

ASCII Encoding Example

Using the ASCII key in Appendix A of the textbook, p. 313Using the ASCII key in Appendix A of the textbook, p. 313(this key uses 7-bit binary ASCII format)(this key uses 7-bit binary ASCII format)

How would we encode INFT 101 into decimal and ultimately binary?How would we encode INFT 101 into decimal and ultimately binary?

I = 73 = 1001001 N = 78 = 1001110 F = 70 = 1000110 T = 84 = 1010100 space = 32 = 0100000 1 = 49 = 0110001 0 = 48 = 0110000 1 = 49 = 0110001

INFT 101 = INFT 101 = 10010011001110100011010101000100000011000101100000110001

DecDecChar.Char. BinaryBinary

Page 19: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

19

ASCII Decoding Example

Decode this binary sequence:

01000011011010000110000101110000011101000110010101110010

One option is to break it down into bytes, translate into decimal numbers, and look up on ASCII chart:

01000011 01101000 01100001 01110000 01110100 01100101 0111001067 104 97 112 116 101 114

C h a p t e r

Page 20: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

20

How Many Bits Are Necessary to Represent Something?

1 bit can represent two (21) symbols either a 0 or a 1

2 bits can represent four (22) symbols 00 or 01 or 10 or 11

3 bits can represent eight (23) symbols 000 or 001 or 011 or 111 or 100 or 110 or 101 or 010

4 bits can represent sixteen (24) symbols 5 bits can represent 32 (25) symbols 6 bits can represent 64 (26) symbols 7 bits can represent 128 (27) symbols 8 bits (a byte) can represent 256 (28) symbols n bits can represent (2n) symbols! So…how many bits are necessary for all 102 of us in class to have a

unique binary ID?

Page 21: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

21

Question

Is 64-bit twice as big as 32-bit? 32 bit = 232 = 4,294,967,296 bits 64 bit = 264 = 1.8 x 1019 bits 128 bit = 2128 = 3.4 x 1038 bits

Is 8-bit twice as big as 4-bit? 8 bit = 28 = 256 bits 4 bit = 24 = 16 bits

Remember that we’re dealing with exponents! 8 bit is twice as big as __________? 7 bit! 7 bits provide 27 possible values or 2x2x2x2x2x2x2 = 128 8 bits provide 28 possible values or 2x2x2x2x2x2x2x2 = 256

Page 22: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

22

Something to Remember

“Bits” are often used in terms of a data rate, or speed of information flow:

56 Kilobit per second modem (56 Kbps) A T-1 is 1.544 Megabits per second (1.544 Mbps or 1544 Kbps)

“Bytes” are often used in terms of storage or capacity--computer memories are organized in terms of 8 bits

256 Megabyte (MB) RAM 40 Gigabyte (GB) Hard disk

Page 23: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

23

Note! The Multipliers for Bits and Bytes are Slightly Different.

When Referring to Bytes (as in computer memory)

Kilobyte (KB) 210 = 1,024 bytes

Megabyte (MB) 220 = 1,048,576 bytes

Gigabyte (GB) 230 = 1,073,741,824 bytes

Terabyte (TB) 240 = 1,099,511,627,776 bytes

When Referring to Bits Per Second (as in transmission rates)

Kilobit per second (Kbps) = 1000 bps (thousand)

Megabit per second (Mbps) = 1,000,000 bps (million)

Gigabit per second (Gbps) = 1,000,000,000 bps (billion)

Terabit per second (Tbps) = 1,000,000,000,000 bps (trillion)

““Kilo” or “Mega” have slightly different values when used with bits Kilo” or “Mega” have slightly different values when used with bits per second or with bytes.per second or with bytes.

Page 24: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

24

More Multipliers for Measuring Bytes

Kilobyte (K) 210 = 1,024 bytes

Megabyte (M) 220 = 1,048,576 bytes

Gigabyte (G) 230 = 1,073,741,824 bytes

Terabytes (T) 240 = 1,099,511,627,776 bytes

Petabytes (P) 250 = 1,125,899,906,842,624 bytes

Exabytes (E) 260 = 1,152,921,504,606,846,976 bytes

Zettabytes (Z) 270 = 1,180,591,620,717,411,303,424 bytes

Yottabytes (Y) 280 = 1,208,925,819,614,629,174,706,176 bytes

Page 25: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

25

New Topics

The Octal Numbering System: What is It and When Would We Use It?

The Hexadecimal Numbering System: What is It and When Would We Use It?

Converting between Binary, Octal, and Hexadecimal

Page 26: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

26

Alternative Notations - Octal and Hexadecimal Representation

Octal--base 8--Uses 8 Numerals 0, 1, 2, 3, 4, 5, 6, 7

Hexadecimal--base 16--Uses 16 Numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

When dealing with collections of bits - for example binary words representing text characters using the ASCII code - it can be inconvenient to deal with each individual bit.

Sometimes it’s necessary to examine particular bit patterns to determine whether a system is operating properly.

For such applications, we find it easier to use a “shorthand” notation, or alternative notation.

Two examples are “octal” and “hex”

Page 27: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

27

Octal A counting system using the first eight numerals starting

with zero. So the first 20 numbers of this system are:

0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23 Because each numeral can only take on one of 8 values, and

because 8 is a power of 2, we can use an octal numeral as shorthand to represent a group of 3 bits:

Octal Numeral Bit Pattern0 0001 0012 0103 0114 1005 1016 1107 111

Page 28: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

28

Converting Binary to Octal

For example, the number 101001010111 may be converted to octal form by grouping the bits into 3.

Starting from the right, break the bit pattern into groups of three:

The first 3-bits are: 111, corresponding to 7. The next 3-bits are: 010, corresponding to 2. The next are 001, corresponding to 1. and the last 3-bits are 101, corresponding to 5.

The above binary number may be represented by: 5127(8) in octal form

Page 29: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

29

Octal Example

If the following 12-bit pattern is stored in a computer’s memory:

010110011101(2)

We can represent these bits in octal as:

2635(8)

Page 30: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

30

In-Class Problems: Binary to Octal Conversion

Convert to octal:

110110101010(2)

100011010(2)

Page 31: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

31

In-Class Problems: Octal to Binary Conversion

Convert to binary:

63(8)

215(8)

Could we convert 291?

Page 32: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

32

Hexadecimal

The “Hex” system uses 16 numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

What are the first 20 numbers of the hex system? 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12, 13

Because each numeral can take on one of 16 values, and because 16 is another power of two, we can use a hex numeral to represent a grouping of four bits.

Page 33: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

33

Comparing Decimal, Octal, Hex, BinaryDecimal Octal Hex Bit Pattern0 0 0 00001 1 1 00012 2 2 00103 3 3 00114 4 4 01005 5 5 01016 6 6 01107 7 7 01118 10 8 10009 11 9 100110 12 A 101011 13 B 101112 14 C 110013 15 D 110114 16 E 111015 17 F 1111

Page 34: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

34

Converting Binary to Hexadecimal

For example, the number 101011010111(2) may be converted to hexadecimal form by grouping the bits into 4 and translated as follows:

Starting from the right, count 4 digits to the left. The first 4-bits are: 0111, corresponding to 7(16).

The next 4-bits are: 1101, corresponding to D(16).

The last bits are: 1010, corresponding to A(16)

The above binary number may be represented by: AD7(16) in hexadecimal form

Page 35: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

35

In-Class Problems

Convert to Hex:

101101110101(2)

Page 36: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

36

In-Class Problems

Convert to Hex:

101110101101(2)

Page 37: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

37

In-Class Problems

Convert to Binary:

ADD1(16)

Page 38: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

38

Converting Octal and Hex to Decimal

To convert octal and hex to decimal, we apply the same technique as converting binary to decimal.

Remember that we summed together the weights of the various positions in the binary number which contained a “1” to convert from binary to decimal.

Similarly, we sum the weights of the various positions in the octal or hex numbers depending on the base being used.

Binary is base 2

Octal is base 8

Hex is base 16

Example of octal to decimal conversion..

Page 39: 1 Introduction to Information Technology BINARY REPRESENTATION OF REAL NUMBERS AND TEXT HEXADECIMAL AND OCTAL Lecture Notes - 2

39

Real World Hexadecimal Examples

Important In-Class Examples

Ethernet Addresses Internet Addresses (IPv6)