bits, data types, and operations: chapter 2 comp 2610 dr. james money comp 2610 1

17
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Upload: charlene-lyons

Post on 13-Dec-2015

218 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bits, Data types, and Operations: Chapter 2

COMP 2610Dr. James Money

COMP 2610

1

Page 2: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bit Vectors

There are many occasions when you want to

store independently whether a particular part

of a system is busy or available

For example, consider tracking whether a

particular taxicab at a company is in use

Page 3: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bit Vectors

To do this, assume we have n units to keep

track

We can use a single bit for each unit, thus

requiring n bits

This is called a bit vector

We arbitrarily assume what 0 and 1 represent

Page 4: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bit Vectors

Suppose we have 8 machines to monitor with

respect to their availability with a 8 bit

BUSYNESS bit vector

Here, 1=unit is free, 0=unit is busy

Bits are labeled right to left, 0 to 7

Page 5: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bit Vectors

Suppose BUSYNESS is 11000010

What does this mean?

What work is assigned to unit 7

What is the new bit vector?

How do we use a logical operation to do this?

( AND 01111111)

Page 6: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Bit Vectors

Suppose unit 5 finishes it’s task

We need to update the BUSYNESS vector

so that unit 5 is free

How do we do this with a logical operation?

Page 7: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Precision

We’ve used 16 bit values to represent our

range of integers

With 16 bits, we can represent 0 to 65535 or

-32768 to 32767 in signed values

That is, the range of values is -215…215-1

Page 8: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Precision

For this case, we say the precision of the

data type is 15 bits and the range is 215

In general, for n bits our signed range is

-2n-1…2n-1-1

This corresponds to a precision of n-1 bits

and a range of 2n-1

Page 9: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

So far, we have only learned how to store

integers on the computer

What if we want to store the number 2.73?

We have to use the floating point data type

We do not use the entire 16 bits to store the

precision of the value

But we do not have enough of a range!

Page 10: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Most ISAs have a data type called float, which

is 32 bits arranged as follows– 1 bit for sign

– 8 bits for range of exponent

– 23 bits for the precision or fraction

This is called the IEEE Standard for Floating

Point Arithmetic

Page 11: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Page 12: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Note the exponent is not allowed to be either 0 or

255

These are special cases for the numbers

This is similar to scientific notation

Recall normalized scientific numbers are in the form

A x 10p

where 1<=A<10

Page 13: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Consider the number 3.75

First convert the number to binary form

– We have (3)10 = (11)2

Now, how about 0.75 part?

We can convert this by multiplying by 2(instead of

dividing)

This moves the decimal one space to the right

Page 14: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

0.75x2 = 1.50

Truncate the whole part and repeat:

0.50x2 = 1.00

0.00x2 = 0.00

So our bits are (11.1100…)2

Page 15: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Now we move the decimal to the left, to get it in

the correct form 1.xxxx:

11.1100 = 1.11100 x 21

So we have S=0, exponent = 127+1=128 =

(10000000)2,

fraction=(111 0000 0000 0000 0000 0000)2

FP Value = 0100 0000 0111 0000 0000 0000 0000 0000

Page 16: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

What does the floating point data type

0011 1101 1000 0000 0000 0000 0000 0000

represent?

S=0, positive

Exponent = (011 1101 1)2 = 123

So, the power is 2123-127=2-4

Page 17: Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610 1

Floating Point Data Type

Fraction = 1.000 0000 0000 0000 0000 0000

Thus, our number is

– 1 x 2-4

– Or 1/16