Arithmetic Flashcards

1
Q

What variable type is the representation of numbers generally based on?

A

Integers

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

How are numbers represented?

A

binary notation

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

Why is range and resolution of the representation limited?

A

Because the number of bits used to represent data is limited

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

What are the three rules for addition in computer arithmetic?

A
  1. 0+0 = 0
  2. 1+0 = 1
  3. 1+1= 10 (0 carry 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

E.g. can you add 96 and 37 in binary?

A

1100000
+0100101
10000101 == 133

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

What is the range number (binary) for unsigned integers using one byte?

A
  • 1 byte = 8 bits

- range: 0 (00000000) to 255 (11111111)

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

What method do we use for negative number notation?

A

Two’s Complement

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

What is the two’s complement rule for changing the sign of a number ?

A
  1. Invert all bits

2. Add 1 to the result?

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

Can you write two’s complement notation for numbers +7 to -8?

A

Yes / no?

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

What rules are used for adding of two’s complement signed integers?

A

same rules for adding unsigned integers

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

E.g. can you do the summation: 3 -2 in twos complement notation? What is wrong?

A

0011
1110
10001
There is an extra 1, called a carry out bit which should be ignored in order to obtain the right answer (1)

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

How can two’s complement theory be summed up in a sentence?

A

Mathematically, we have defined that if A is an n-bit binary number, then -A is represented as 2^(n)-A. (this turns out to be the same as inverting all the bits and adding one)

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

How is multiplication by the nth power of 2 done? can you do 5 * 2 in binary?

A

Simply by shifting the data to the left n places.

00101

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

How is division by the nth power of 2 done? Can you do 12/ 2 in binary?

A

Simply by shifting the data right n places.

1100&raquo_space; 0110 (6)

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

How can we divide and multiply by non powers of 2? Can you do 3 * 10 in binary?

A

Using a combination of shifting and adding:
310 = 32^3 + 3*2^1
= 0011

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

What is overflow?

A

When an arithmetic operation results in a value that is outside the range which can be represented by the variable.

17
Q

What happens if overflow occurs when a variable is represented by >1 byte?

A

The lower byte results in a carry bit being taken to the higher byte:
high byte 00000000 00000001
low byte 11000001 *2 (

18
Q

How can integers represent fractions?

A

Decimal numbers can be scaled to be represented by integers

19
Q

Example: a thermometer measures temps between -40 and 60 degrees. We are using an 8bit ADC. How can the degrees be mapped to units?

A

8bit ADC - measurements must fit into one byte.

We map -40 degrees to 0 and 87.5 degrees to 255… (with numbers inbetween e.g. -39.5 maps to 1)

20
Q

What value is 000101.11 in fixed (binary) point notation?

A

2^2 + 2^0 + 2^-1 + 2^-2 = 5.75

21
Q

What is the disadvantage of fixed point numbers?

A

The binary point is at a fixed location so the range and resolution are limited. E.g. in q20 notation (assuming unsigned numbers) the range is 0 ….63.75 and the maximal resolution is 2^(-2) , 0.25

22
Q

Why is floating point notation used?

A

To cope with very large and very small numbers.

23
Q

E.g. how may 11011100.0 be written in floating point notation?

A

1.1011100 * 2^7 (note first bit of the number is always1)

24
Q

What is the standard IEEE 754 notation?

A

(-1)^s * (1+F) * 2^E

25
Q

What do s, F and E represent in IEEE 754 notation?

A
s = sign
F = fraction
E = exponent
26
Q

How is the single precision format represented?

A
  • 32 bit
  • s = 0 (positive) or 1 (negative) [1 bit]
  • Exponent E = -126 …. 127 [8 bits]
  • Fraction F = bit 222^-1 …. bit02^-23 [23 bits]
27
Q

How is zero defined in IEEE 754 floating point notation?

A

If E = 0 and F = 0

28
Q

How is infinity defined in IEEE 754 floating point notation?

A

If E=Emax and F=0

29
Q

How is not a number defined in IEEE 754 floating point notation?

A

If E=Emax and F!=0 (NaN)

30
Q

What is the main reason for using double precision numbers (8bytes) instead of single precision numbers (4bytes)?

A

Not the increased range but the improved precision

31
Q

What is the precision of a single precision number?

A

Fractional part originally 1 + 0
Next number 1 + 2^-23
Precision is 2^-23 in 1 i.e. 1 part in 2^23
or 1 part in 10^7

32
Q

What is the precision of a double precision number?

A

Fractional part originally 1+0
Next number 1 + 2^-52
Precision is 1 part in 2^52 or 1 part in 10^15

33
Q

Name 6 types of integers?

A

byte, short, int, unsigned int, long, unsigned long

34
Q

how many bits in a short?

A

16 bits

35
Q

How to work out the range for an unsigned integer?

A

from 0 to 2^n -1 where n is the number of bits

36
Q

How to work out the range for a signed integer?

A

lowest -2^(n-1) - 1 and highest 2^(n-1)

37
Q

What are the two conclusions that can be made about the efficiency of types of arithmetic?

A
  1. using integer arithmetic is much more efficient than using floating point: the logic circuits for integer arithmetic are very simple, whereas floats require complex operations
  2. Using mcs native data size is most efficient (but might use more memory). Other data sizes require additional memory operations.