Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
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 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 )
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 or to in signed values That is, the range of values is …
Precision For this case, we say the precision of the data type is 15 bits and the range is 2 15 In general, for n bits our signed range is -2 n-1 …2 n-1 -1 This corresponds to a precision of n-1 bits and a range of 2 n-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
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 10 p 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 = x2 = 0.00 … So our bits are ( …) 2
Floating Point Data Type Now we move the decimal to the left, to get it in the correct form 1.xxxx: = x 2 1 So we have S=0, exponent = 127+1=128 = ( ) 2, fraction=( ) 2 FP Value =
Floating Point Data Type What does the floating point data type represent? S=0, positive Exponent = ( ) 2 = 123 So, the power is =2 -4
Floating Point Data Type Fraction = Thus, our number is – 1 x 2 -4 – Or 1/16