131 Week 2 - Information Coding Flashcards
Why do we need information coding
To allow for more complex data and data types to exist but still be coded into (or represented as) something that is cheap and easy to store and process.
Computer hardware handles data types and data as small positive whole numbers.
ASCII
American Standard Code for Information Interchange
Defines 128 (2^7) symbols - 7 bit binary.
How can negative numbers be represented?
Sign and magnitude, excess n
Sign and magnitude
A character is used to represent if a number is negative or positive. It is then followed by the magnitude of the number.
It works however a column is sacrificed and 0 can be represented twice as it can be positive or negative.
Excess n
Uses n as a new value for 0. Any positive number is added to the n and any negative number is subtracted from the n.
e.g., 150 in excess 5000 is 5150. -25 in excess 5000 is 4975.
It doesn’t use an extra column and has a single value for 0.
How can decimal numbers be represented?
Fixed point, floating point
Fixed point decimals
Some columns are reserved for the fractional part of a number.
However this is not a very efficient use of columns.
Floating point decimals
Trades precision for range by using a mantissa and exponent to represent numbers. Mantissa and exponent are represented with sign and magnitude.
Mantissa * Radix^exponent
Radix
The amount of characters a number system uses to represent numbers.
Also called the base
Denary (decimal)
A way of representing numbers using 0-9
Radix (base) 10
Binary
A way of representing numbers using 0,1
Radix (base) 2
Octal
A way of representing numbers using 0-7
Radix (base) 8
Hexadecimal
A way of representing numbers using 0-9, A-F
Radix (base) 16
Addition rules for adding binary numbers
0+0=0
1+0=1
0+1=1
1+1=0 carry 1
1+1+1=1 carry 1
Problems with sign and magnitude and excess n arithmetic
Sign and magnitude: doesn’t deal with overflow
Excess n: x – y ≠ x + (-y)
Would need extra hardware to be able do subtraction as well as addition for excess n. This would be less space and cost effective.
2’s Complement
A way of representing negative numbers where they can be added and subtracted from each other.
Converting +ve to -ve in 2’s complement
Start with the equivalent positive number
Flip all bits (0 to 1, 1 to 0)
Add 1 to the number, ignoring overflow.
IEEE 754 Standard floating point
Mantissa is coded in sign and magnitude
Exponent is coded in excess n
Has multiple precisions: half, single, double, quadruple.
Single precision IEEE 754
Uses 32 bits overall
First bit is used for mantissa sign bit
Next 8 bits used for exponent in excess 127
Remaining 23 bits used for mantissa magnitude.
How is the mantissa normalised for IEEE 754
Mantissa is always normalised to start as 1.xxxxx
The first bit then does not has to be stored as it will always be 1. and can just be assumed to be so.