Title: Real Time Systems
1Chapitre 2 Représentations Internes des données
2Binary Numbers
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Binary 0000 0001 0010 0011 0100 0101 0110 0111 10
00 1001 1010 1011 1100 1101 1110 1111
Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
3Binary NumbersSome useful values
128 256 1 024 32 768 65 536 2 147 483 148 4 294
967 296
27 28 210 215 216 231 232
? 103
4Data Representations
- Text
- Baudot - ASCII - UNICODE
- Numbers
- Decimal - Binary / Integer - Floating point
- Images
- Bitmaps - Structured
5Text Encoding
- Telex public network
- 5 bit/char BAUDOT code (Alph. Num. Mode)
- Older computers (fifties and sixties)
- 6 bit proprietary codes (no lower case)
- IBM mainframes and compatibles
- 8 bit EBCDIC code
- Vast majority of modern computers
- 7 bit ASCII (no national characters)
- 8 bit ASCII with proprietary extensions
- Microsoft NT systems
- 16 bit Unicode for all known character-sets
- ASCII is a subset of Unicode
6Baudot Character Set (CCITT Nr 2)Alphabetical
State
7Baudot Character Set (CCITT Nr 2)Numerical State
8Printable ASCII Character Set
047
/
063
?
079
O
095
_
111
o
9ASCII special characters
128
DEL
Delete
10ASCII extensions for pc
_
207
223
239
255
11Unicode
FFFF
12Decimal Numbers
ASCII Characters 8 bit / digit. BCD Characters
4 bit / digit.
Example In a 32 bit word
13Absolute Value Sign
- Conventions
- n number of bits in representation
- M value to be represented
- M' value of representation
- Absolute Value Sign definition
- M gt 0 M' M
- M lt 0 M 2n-1 M
- Range
- - 2 n-1 lt M lt 2 n-1
14Absolute Value Sign
0
1
-7
0000
0001
1111
2
-6
0010
1110
3
-5
0011
1101
1100
0100
4
-4
n 4
0101
1011
5
-3
0110
1010
6
-2
1001
0111
1000
-1
7
-0
15Binary Offset
- Conventions
- n number of bits in representation
- M value to be represented
- M' value of representation
- Binary offset definition
- M 2n-1 M
- Range
- - 2 n-1 lt M lt 2 n-1
16Binary Offset
-8
-7
7
0000
0001
1111
-6
6
0010
1110
-5
5
0011
1101
1100
0100
-4
4
n 4
0101
1011
-3
3
0110
1010
-2
2
1001
0111
1000
1
-1
0
17Twos complement
- Conventions
- n number of bits in representation
- M value to be represented
- M' value of representation
- Two's complement definition
- M' (M 2n) MOD 2n
- Range
- - 2 n-1 lt M lt 2 n-1
18Twos Complement
0
1
-1
0000
0001
1111
2
-2
0010
1110
3
-3
0011
1101
1100
0100
4
-4
0101
1011
5
-5
0110
1010
6
-6
1001
0111
1000
-7
7
-8
19Some Twos Complement Numbers
4 bit
value
8 bit
16 bit
-32768
20Twos complement Arithmetic
All arithmetic operations can be performed on
the twos complement representations, using
positive, modulo 2n arithmetic.
A 3 B -5
A 3 B 27
0 0 0 1 1 1 1 0 1 1
0 0 0 1 1
0 0 0 1 1
n 5
0 0 0 0 0
0 0 0 1 1
0 0 0 1 1
0 0 1 0 1 0 0 0 1
A B - 15
21Twos complement Arithmetic
All arithmetic operations can be performed on
the twos complement representations, using
positive, modulo 2n arithmetic.
S A B with A gt 0 and B gt 0
A A B B
S (A B) MOD 2n A B S
Provided, of course, that S lt 2 n-1
22Twos complement Arithmetic
All arithmetic operations can be performed on
the twos complement representations, using
positive, modulo 2n arithmetic.
S A B with A gt 0 and B lt 0
A A B B 2 n 2 n - B
S (A B) MOD 2n (A - B 2 n) MOD
2n Suppose A gt B (? S gt 0) then A - B
2 n gt 2n and S A - B S Suppose A lt B
(? S lt 0) then A - B 2 n lt 2n and S A
- B 2n S 2n
23Twos complement Arithmetic
All arithmetic operations can be performed on
the twos complement representations, using
positive, modulo 2n arithmetic.
S A B with A lt 0 and B lt 0
A A 2n 2n - A B B 2n 2n - B
S (A B) MOD 2n (2.2n -(A B)) MOD
2n Where 2 lt A B lt 2n-1 therefore
2n1-2 gt (2.2n -(A B)) gt 3.2n-1 and
(2.2n -(A B)) MOD 2n (2.2n- 2n
-(A B)) or S (2n -(A
B)) 2n S
24Twos complement Arithmetic
All arithmetic operations can be performed on
the twos complement representations, using
positive, modulo 2n arithmetic, provided that the
result is in range.
25Twos complement Overflow
- With a 16 bit representation
- 30 000 10 000 - 7 232 !!!
26With thanks to Ariane for the score
27Twos complement Overflow
No carry from n-2 to n-1, nor from n-1 to n.
Carry from both n-2 to n-1, and n-1 to n.
28Extended Multiplication
In general, two n bit factors give a 2n bit
product ! Simplest algorithm to compute a n bit
product Sign extend both factors to 2 n
bit Perform the multiplication modulo 2 2n
A 3 B -5
A 3 B 27
0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
n 4
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1
1 1 1 1 0 0 0 1
A B - 15
29Ones complement
- Conventions
- n number of bits in representation
- M value to be represented
- M' value of representation
- Two's complement definition
- M gt 0 M' M
- M gt 0 M' M 2n - 1
- Range
- - 2 n-1 lt M lt 2 n-1
30Ones Complement
0
1
-0
0000
0001
1111
2
-1
0010
1110
3
-2
0011
1101
1100
0100
4
-3
0101
1011
5
-4
0110
1010
6
-5
1001
0111
1000
-6
7
-7
31REAL TypesApproximate representation for real
numbers
- Possible values and accuracy
- implementation dependant
- majority of computer systems IEEE754.
- Single precision (32 bit) float
- Smallest value 10-38
- Largest value 1038
- Relative error lt 3 10-8
- Double precision (64 bit) double
- Smallest value 10-308
- Largest value 10308
- Relative error lt 10-16
32Floating Point Numbers
base predefined constant (2 or 16)
Normalized Floating Point Number
33Normalizationon a scale...
34Relative erroron Normalized Floating Point
Numbers
35Gradual Underflow
Normalized Underflow
0
1000.2
min1
1001.2
min
min
1000.2
36Floating Point NumbersIEEE 754, Short Real
Sign
Significand
Exponent
Value
(-1)Sign 1.Significand 2 Exponent - 127 ?
0
(-1)Sign 0.Significand 2 - 126 0
37Floating Point NumbersIEEE 754, Short Real
Sign
Significand
Exponent
Smallest 10 - 38 Largest 10 38 Rel.Error
3.0 10 - 8
38Floating Point NumbersIEEE 754, Long Real
Sign
Significand
Exponent
Value
(-1)Sign 1.Significand 2 Exponent - 1023
? 0
(-1)Sign 0.Significand 2 - 1022 0
39Floating Point NumbersIEEE 754, Long Real
Sign
Significand
Exponent
Smallest 10 - 308 Largest 10
308 Rel.Error 1.1 10 - 16
40Floating Point NumbersIEEE 754, Temporary Real
Sign
Significand
Exponent
Value
(-1)Sign Significand 2 Exponent - 16383 ?
0
(-1)Sign Significand 2 - 16382 0
Significand 1.XXXX or 0.XXXX
41Floating Point NumbersIEEE 754, Temporary Real
Sign
Significand
Exponent
Smallest 10 - 4932 Largest 10
4932 Rel.Error 5.4 10 - 20
42Floating Point NumbersIEEE 754, Special values
- Zero
- Exponent all 0s
- Significand all 0s
- Infinity
- Exponent all 1s
- Significand all 0s
- Not a Number
- Exponent all 1s
- Significand any non zero value
43Encoding of Images
- By means of bit maps
- Each pixel is represented by one or several
bytes. - By means of image components
- ASCII codes for letters
- Coordinates of end points for vector.
- Coordinates of center radius for circle.
44A bit map
Size 10 MBytes
45An other bit map
Size 10 MBytes
46A geometric construct
Size 13 KBytes
47Alphanumeric Display
Number of character positions 80 24
1920. Number of different characters 256,
encoded by 8 bit. Number of bytes for entire
screen 1920. Number of pixels per character
8 20 160. Number of pixels on screen
1920 160 307 200 38 400 bytes
48Data Compression
Four colours encoding 1000 colours, non-uniform
distribution
49Data Compression
Four colours encoding 1000 colours, uniform
distribution
frequency
code
nbr of bits
code
nbr of bits
red
25
00
500
0
250
blue
25
01
500
10
500
green
25
10
500
110
750
yellow
25
11
500
111
750
50Data CompressionShannons Law
Minimal Number of bits per symbol
nmin - ?ipi log2 pi
In the four colours example
51Data Compression
- Entropy coding
- based on symbol frequency
- No loss of information
- used for data compression and storage
- Examples
- Huffman coding variable length codes
- See colors example
- run length encoding repetition factors
- 123333320000000123333333311111112234
- 12532701283712234
- Example Zip - Unzip
52Data Compression
- Source coding
- based on meaning of data
- acceptable loss of information
- used for data compression and storage
- spectacular compression rates
- Examples
- GSM vocoders only for human voice
- 64 Kb/s gt 13 Kb/s or 6.5 Kb/s
- JPEG still images, compression 120
- MPEG TV images, compression 1100