Binary can represent negative numbers there are two way to do this:
Sign and magnitude:
- Simplest way
- The most significant bit represents the sign (whether it is positive or negative)
- 1 means it is negative
- 0 means it is positive
- However the MSB means that the largest number for 8 bits that can be represented as 127, as the 8th bit is used for the positive or negative sign.
- Only represent a 7 bit number
- It is harder to do calculations as some bits are numbers and some are for signs.
- 0 is represented twice
- 127 to -127 range
Represent -4 in 8 bits:
4=00000100
-4= 10000100
Two's Complement:
If in the exam it says it represented in Two's Complement the whole binary number will be wrong.
- Overcomes the shortcomings of S/M as the whole number range can be represented
- Write out as a positive number then starting from the right hand side invert bits.
- The most significant bit becomes a negative number
90=01011010
-90=10100110
0+0 = 0
1+0 = 1
1+1 = 10
1+1+1= 11
Hexadecimal:
- 0 to 15 using 0-9 and A to F
- Represented in 4 bits per hex character
- We use this to represent really small or really big numbers accurately using 8 bits
0.92 x10^2
0.92 is the mantissa this represents significant digits of that number
10 is the base
2 is the exponent (How far the mantissa is to be raised)
01101 011
Where 01101 is the mantissa and 011 is the exponent
Steps to take:
1. Convert the exponent into denary
2. The mantissa started as 0.1101. Move the decimal point 3 places to get 0110.1
3. Write 0110.1 as denary 6.5 (4+2+0.5)
If there is more than one leading 0 this will be classed as an un-normalised number. The decimal goes after the first 0
Shift by the exponent of 3
0110.1
Left bits go by 1,2,4
Right bits go by 1/2, 1/4, 1/8, 1/6
There is a trade off between accuracy and range depending on how many bits are used for the exponent and mantissa.
More bits for the mantissa = more accuracy
More bits for the exponent = more range
No comments:
Post a Comment