Arithmetic Flashcards
What variable type is the representation of numbers generally based on?
Integers
How are numbers represented?
binary notation
Why is range and resolution of the representation limited?
Because the number of bits used to represent data is limited
What are the three rules for addition in computer arithmetic?
- 0+0 = 0
- 1+0 = 1
- 1+1= 10 (0 carry 1)
E.g. can you add 96 and 37 in binary?
1100000
+0100101
10000101 == 133
What is the range number (binary) for unsigned integers using one byte?
- 1 byte = 8 bits
- range: 0 (00000000) to 255 (11111111)
What method do we use for negative number notation?
Two’s Complement
What is the two’s complement rule for changing the sign of a number ?
- Invert all bits
2. Add 1 to the result?
Can you write two’s complement notation for numbers +7 to -8?
Yes / no?
What rules are used for adding of two’s complement signed integers?
same rules for adding unsigned integers
E.g. can you do the summation: 3 -2 in twos complement notation? What is wrong?
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 can two’s complement theory be summed up in a sentence?
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 is multiplication by the nth power of 2 done? can you do 5 * 2 in binary?
Simply by shifting the data to the left n places.
00101
How is division by the nth power of 2 done? Can you do 12/ 2 in binary?
Simply by shifting the data right n places.
1100»_space; 0110 (6)
How can we divide and multiply by non powers of 2? Can you do 3 * 10 in binary?
Using a combination of shifting and adding:
310 = 32^3 + 3*2^1
= 0011
What is overflow?
When an arithmetic operation results in a value that is outside the range which can be represented by the variable.
What happens if overflow occurs when a variable is represented by >1 byte?
The lower byte results in a carry bit being taken to the higher byte:
high byte 00000000 00000001
low byte 11000001 *2 (
How can integers represent fractions?
Decimal numbers can be scaled to be represented by integers
Example: a thermometer measures temps between -40 and 60 degrees. We are using an 8bit ADC. How can the degrees be mapped to units?
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)
What value is 000101.11 in fixed (binary) point notation?
2^2 + 2^0 + 2^-1 + 2^-2 = 5.75
What is the disadvantage of fixed point numbers?
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
Why is floating point notation used?
To cope with very large and very small numbers.
E.g. how may 11011100.0 be written in floating point notation?
1.1011100 * 2^7 (note first bit of the number is always1)
What is the standard IEEE 754 notation?
(-1)^s * (1+F) * 2^E