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