Binary Arithmetic Flashcards
What symbols does the binary number system use?
It uses 2 symbols: 0 and 1
eg. 19 in binary is 10011
What is the right-most digit called?
Least Significant Bit (LSB)
What is the left-most digit called?
Most Significant Bit (MSB)
What is the highest number that we can represent in binary with N digits?
2N - 1
What does Q3 format mean?
It has 3 bits after the binary point (binary equivalent of decimal point)
How do you convert from decimal to binary?
Do repeated division by 2 until you get 1. The remainders are the bits starting from the LSB
What is a flag?
A binary number only having 1 bit
What is a nibble?
A binary number having 4 bits
What is a byte?
A binary number having 8 bits
What is a word?
A binary number having 16 or more bits
How do you carry out binary addition?
110 + 101 Going from LSB 0+1 = 1, carry out = 0 1+0 = 1, carry out = 0 1+1 = 0, carry out = 1
SUM = A=OB C = A.B
What does the half adder do?
- Generates the sum and carry-out for one column of an addition sum
- BUT it does not allow for a carry-in from a previous column (this can be done with a full adder circuit)
Describe how a full adder works
- The full adder uses 2 half adders; one to form the sum of A and B and another to add any carry in to this intermediate sum.
- If EITHER of the two additions generates a carry-out, we must indicate that by setting the final carry out to 1.
[HALF ADDER then HALF ADDER then OR gate]
How do you built a multi-bit full adder?
- A row of N full adders would be required and the result has to be (N+1 bits in the case of overflow).
(this is catered for by carry out being the MSB
How do you represent negative numbers in binary?
2’s complement
[Half the possibilities for positive numbers and negative numbers, let the MSB have a negative weighting}
How do you differentiate between positive and negative signed numbers?
- Signed numbers are positive if the MSB is 0
- Signed numbers are negative if the MSB is 1
How do you carry out binary subtraction using 2’s complement?
1) Invert all the bits (eg. 0011 turns to 1100)
2) Add 1 (1100 + 1 = 1101)
NOTE: doesn’t work for the maximum negative number
Calculate 4 minus 3 in binary
Convert to binary
4 = 0100
3 = 0011
Convert negative number to 2’s complement
-3 = 1101
Perform binary addition
0100 + 1101 = 10001
Discard carry out
=0001 (final answer)
How do you prevent overflow when adding two N-bit signed numbers?
1) Sign extend to N + 1 bits
2) Use an N + 1 bit adder
How do you extend a number of have more bits in signed binary?
Duplicate the MSB
eg.
- Converting 0011 into 8 bits gives 00000011
- Converting 1011 into 8 bits gives 11111011
This is called signed extension
How do you build a subtraction machine?
Use an array of full adders but before that, pass all the B-input bits through inverters.
Then set the carry-in to 1 on the least significant full adder.
What is a use of XOR gates?
They can be used as controllable inverters
What is the difference between Unsigned and Signed values?
Unsigned
- MSB has a positive value
- The carry out from the MSB of an adder can be used as an extra bit of the answer to avoid overflow
- To increase the umber of bits, add zeros to the left hand side
- Complementing and adding 1 converts X to (2N - X)
Signed
- MSP has a negative value
- To avoid overflow, we need to sign extend then use and adder with one more bit than the numbers to be added
- TO increase the number of bits, sign extend by duplicating the MSB
- Complementing and adding 1 converts X to - X