Part 1 Block 1 - Floating Point Flashcards
Convert the following binary number into decimal.
101.011
5.375
To represent a float in binary scientific notation, we have powers of ____ (rather than powers of 10) and the mantissa always starts with a ___________, followed by a decimal point.
powers of 2
starts with a 1
So, –10101.1 in binary notation can be written as –1.01011 × 2^_________ in binary scientific notation.
2^4
In Binary Scientific notation, where is the ‘sign’ stored, and how is a positive and a negative sign represented?
The sign in stored in the leftmost bit.
1 = negative
0 = positive
In a typical computer, a float is stored in _____ bytes
4 bytes
(so, 32 numbers)
Binary Scientific Notation
As we know, the sign is stored in the first bit on the left. What do the next 8 bits store?
The exponent part (aka - the main number before the decimal point)
Binary Scientific Notation
What do the last 23 bits store?
The fractional part of the Mantissa.
When representing a fraction like 1/3 in decimal, we can only make an approximation of it, e.g. 0.3 or closer 0.33, or closer 0.333.
Can we get closer to the fraction in a binary representation, i.e. by adding more and more bits in a similar way?
No, we cannot.
In decimal which part of the following number is the mantissa?
6.02 x 10^23
6.02
In decimal which part of the following number is the exponent?
6.02 x 10^23
23
When programming in any language why should we never compare floats?
e.g is 0.1 + 0.1 + 0.1 == 0.3?
We would get an unexpected answer of false due to the precision problems of Binary.
0.1 in binary is represented as:
0.00011001100110011001100110011001100110011001100110011010
This is actually:
0.1000000000000000055511151231257827021181583404541015625 in denary, so we are not going to get 0.3 if we add that number together three times!
In Python, if we use the .round( ) method,
would we round the seven up, down or leave it as 7?
7.432
leave it as 7
In Python, if we use the .round( ) method,
would we round the 7 up, down or leave it as 7?
7.624
Round up
In Python, if we use the .round( ) method,
would we round the 7 up, down or leave it as 7?
7.544
It would be rounded up, as 7 is an odd number.
In Python, if we use the .round( ) method,
would we round the 12 up, down or leave it as 12?
12.567?
Leave it as 12.
12 is an even number.
Even numbers and zeros remain the same.
Using the .round( ) method, round the following number to 2.d.p.
2.674
2.67
Using the .round( ) method, round the following number to 2.d.p.
2.676
2.68
Using the .round( ) method, round the following number to 2.d.p.
2.685… and 2.675
2.68
Strange things can happen because of the imprecise representations of binary numbers. For example, in order to round 2.675 to two decimal places, you would execute the statement:
round(2.675, 2)
You would expect the answer to be 2.68; however, the value 2.67 is returned.
Why does this happen, and what is the significance?
The number 2.675 cannot be exactly represented in binary notation.
The closest value to 2.675 that can be stored in 53 bits is equivalent to:
2.67499999999999982236431605997495353221893310546875.
The significance is that we might get unexpected results due to precision issues.
In computer programming, an overflow occurs when an arithmetic operation attempts to create a numeric value that is ______________ to be represented within the available storage space.
too large
An example of overflow would be having 4-bits available to represent a number, but then having an addition like:
1111 + 1
This would = 10000 (5-bits)
How would most computer languages deal with this and does two’s complement deal with this in the same way?
They would drop the most significant bit, so 10000 would become 0000
Two’s complement does not do this!
When dealing with f_________, a related problem of underflow can occur
floats
(Underflow)
Using signed-magnitude representation what is the smallest exponent that we could represent with 4-bits?
1111
which is -7 in binary
(Underflow)
The float 0.00000027 can be represented correctly as 2.7 × 10^-7
Can we represent and exponent of -7 using 4-bits?
Yes.
We could use sign-magnitude representation whereby the first digit on the left would represent the sign, so,
(1)111 or 1111
(Underflow)
How could we represent the following decimal in scientific notation?
0.0000000027
Can we represent the resulting negative exponent using sign-magnitude representation and only 4-bits?
How many bits would we need to represent an exponent of -9?
2.7 × 10^–9
No, the lowest number that we can represent in 4-bits using sign-magnitude representation is -7.
We would need 5-bits to represent -9.
(1)1001 is really 11001
Underflow occurs when the numeric value of the mantissa is too ___________ to be stored in the available space.
small
What does Python do to deal with the problem of Underflow and Overflow?
It automatically bumps up the amount of storage as necessary to reduce the risk of an underflow or overflow occurring.
Show that the largest integer that can be represented in a 4-byte two’s complement system is 2,147,483,647.
2^32 = 4,294,967,296
4,294,967,296 / 2 = 2,147,483,647