Data Rep & Number Systems Flashcards
1 byte = ? bits
8 bits
N bits can represent up to how many values?
2^N values
Unsigned vs Signed
Unsigned = only non-negative values Signed = all values (positive & negative)
What are the 3 common representations for signed binary numbers
- Sign-and-magnitude
- 1s Complement
- 2s Complement
What is the range for an 8-bit for the 3 common representations?
Sign-and-Magnitude:
-127 to +127, +0 and -0
1s complement:
same as ^ (-(2^(n-1) - 1) to 2^(n-1)-1)
2s complement:
0 is associated with the positive side, which means positive side get to represent 1 less.
-(2^(n - 1)) to 2^(n-1) - 1
What are the shortcuts for deriving the complements?
1s complement:
Invert all the bits
2s complement:
Invert all the bits then add 1
What is the algorithm for addition/subtraction using both complement systems?
- Perform addition for both
- Check for overflow:
1. + and + = -
2. - and - = +
1s complement:
Add back the carry out of the MSB
2s complement:
Ignore the carry out of the MSB
What is the purpose of excess representation?
Allows the range of values to be distributed evenly between the positive and negative values.
It shifts all the values by Excess-N amount.
The MSB denotes whether is it negative/positive:
0 -> negative
1 -> positive
Usually N is determined by the taking 2^(number of bits - 1) or 2^(number of bits - 2).
What are the different components in an IEEE 754 Floating-Point rep?
- Convert the decimal into binary
- Normalise the binary
- Sign:
0 for positive
1 for negative - Exponent:
Uses excess-127 representation
127 + the power derived from normalising, then convert to binary - Mantissa
Normalised with an implicit leading bit 1
Copy over the values in the fraction portion