Part 1 Block 1 - Floating Point Flashcards

1
Q

Convert the following binary number into decimal.

101.011

A

5.375

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

powers of 2

starts with a 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

So, –10101.1 in binary notation can be written as –1.01011 × 2^_________ in binary scientific notation.

A

2^4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Binary Scientific notation, where is the ‘sign’ stored, and how is a positive and a negative sign represented?

A

The sign in stored in the leftmost bit.
1 = negative
0 = positive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In a typical computer, a float is stored in _____ bytes

A

4 bytes
(so, 32 numbers)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Binary Scientific Notation

As we know, the sign is stored in the first bit on the left. What do the next 8 bits store?

A

The exponent part (aka - the main number before the decimal point)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Binary Scientific Notation

What do the last 23 bits store?

A

The fractional part of the Mantissa.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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?

A

No, we cannot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In decimal which part of the following number is the mantissa?

6.02 x 10^23

A

6.02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In decimal which part of the following number is the exponent?

6.02 x 10^23

A

23

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When programming in any language why should we never compare floats?

e.g is 0.1 + 0.1 + 0.1 == 0.3?

A

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!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In Python, if we use the .round( ) method,
would we round the seven up, down or leave it as 7?

7.432

A

leave it as 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In Python, if we use the .round( ) method,
would we round the 7 up, down or leave it as 7?

7.624

A

Round up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In Python, if we use the .round( ) method,
would we round the 7 up, down or leave it as 7?

7.544

A

It would be rounded up, as 7 is an odd number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In Python, if we use the .round( ) method,
would we round the 12 up, down or leave it as 12?

12.567?

A

Leave it as 12.

12 is an even number.
Even numbers and zeros remain the same.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Using the .round( ) method, round the following number to 2.d.p.

2.674

17
Q

Using the .round( ) method, round the following number to 2.d.p.

2.676

18
Q

Using the .round( ) method, round the following number to 2.d.p.

2.685… and 2.675

19
Q

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?

A

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.

20
Q

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.

21
Q

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?

A

They would drop the most significant bit, so 10000 would become 0000

Two’s complement does not do this!

22
Q

When dealing with f_________, a related problem of underflow can occur

23
Q

(Underflow)

Using signed-magnitude representation what is the smallest exponent that we could represent with 4-bits?

A

1111
which is -7 in binary

24
Q

(Underflow)

The float 0.00000027 can be represented correctly as 2.7 × 10^-7

Can we represent and exponent of -7 using 4-bits?

A

Yes.

We could use sign-magnitude representation whereby the first digit on the left would represent the sign, so,
(1)111 or 1111

25
(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
26
Underflow occurs when the numeric value of the mantissa is too ___________ to be stored in the available space.
small
27
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.
28
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
29