Other Data Types, Part I

Download Report

Transcript Other Data Types, Part I

1
Bits, Data types, and Operations:
Chapter 2
COMP 2610
Dr. James Money
COMP 2610
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
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
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
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)
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?
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
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
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!
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
Floating Point Data Type
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
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
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
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
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
Floating Point Data Type

Fraction = 1.000 0000 0000 0000 0000 0000

Thus, our number is
–
1 x 2-4
–
Or 1/16