n301/cs05othernum
n301.tplt
Sign/magnitude notation
Binary digits can be used to represent not only whole numbers but also other forms of data, including signed integers, decimal numbers and characters.
To represent signed integers, we can use the leftmost bit to represent the sign, 0 meaning + and 1 meaning -
Examples:
The number –49 would be represented as:
1 110001
- 49
What about the binary number 1000000 and the binary number 0000000?
Ones Complement
Possible solution to the problem
The names comes from the fact that it is obtained by subtracting each digit of the input number from 1
However, two’s complement is the better solution – this is when 1 is added to the ones-complement
Adding Negative Numbers
Let’s calculate: 4 + (-6) using twos complement:
| - 8 | 4 | 2 | 1 |
|---|
| 0 | 1 | 0 | 0 |
|---|
| 1 | 0 | 1 | 0 |
|---|
Try another
Calculate 5 + (-2) in binary
PAUSE
Pause the tape to do the calculation. When done, come back to see how it is done.
Compare
Is 10 the same as 110?
Floating Point
Also known as scientific notation
The number 1,023,48710 is 1.023487 * 106
The number 0.102348710 is 1.023487 * 10-1
Binary
The number 101001001112 is 1.0100100111 * 210
The number .00112 is .11 * 2-2
Conversion table (floating pt.)
| 1/2 | 1/4 | 1/8 | 1/16 | 1/32 |
|---|
| .5 | .25 | .125 | .0625 | .03125 |
|---|
| | | | | |
|---|
Examples:
Convert .625 into binary
.625 * 2 = 1.250 (extract the 1)
.250 * 2 = 0.500 (extract the 0)
.500 * 2 = 1.000 (extract the 1)
The digits extracted are taken in the order extracted. In this case, the result is .101 (1/2 + 1/8 = 5/8 = .625)
Errors
One source of errors is converting back and forth between decimal and binary
Example:
calculate .6 + .6
first convert to binary .6
.1001100110011……
Do the math
Find the sum
.10011001
+.10011001
1.00110010
Convert back
So, 1.00110010 converts to 1 + 1/8 + 1/16 + 1/128 = 1.195 (actual sum = 1.2)
Error = 1.2 – 1.195 = .005 due to round off error made during conversions
Normalized form
In normalized form the leading 1 appears next to the decimal point.
Example:
.11001001
Scientific notation
Avagadro’s number: Na = 6.022 * 10 23
Floating point
A BBBB C DD form (8 bits)
A = sign of the mantissa | BBBB = mantissa | C = sign of the exponent | DD = exponent
Example:
+.1011 * 2+3
0 | 1011 | 0 | 11
Example
sign of mantissa | | sign of exponent | |
| A | B | B | B | B | C | D | D |
| digits of mantissa | | digits of exponent |