Sean Barker
Data Representation
1 Sean Barker
Typical Data Sizes
2
Data Type Bytes char 1 short 2 int 4 long 8 float 4 double 8
Data Representation Sean Barker 1 Typical Data Sizes Data Type - - PDF document
Data Representation Sean Barker 1 Typical Data Sizes Data Type Bytes char 1 short 2 int 4 long 8 float 4 double 8 Sean Barker 2 Numbering Systems Decimal Binary Hex 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5
Sean Barker
1 Sean Barker
2
Data Type Bytes char 1 short 2 int 4 long 8 float 4 double 8
Sean Barker
3
0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 A 10 1010 B 11 1011 C 12 1100 D 13 1101 E 14 1110 F 15 1111 Hex Decimal Binary
Sean Barker
4
Sean Barker
5
128 (10000000) 64 192 255 (11111111) Addition 256.
Unsigned numbers!
Sean Barker
6
A 1
127
= 01111111 10000001 = = 10000000
Sean Barker
7
B 1 127
From now on, unless we explicitly say otherwise, we’ll assume all integers are stored using two’s complement! This is the standard!
From now on, unless we explicitly say otherwise, we’ll assume all integers are stored using two’s complement! This is the standard!
= 01111111 = 10000000 10000001 =
Sean Barker
8
Signed& 1 2 3 4 5 6 7
Unsigned& 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Bits& 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
+/:&16&
Sean Barker
9
0101 00000101 1100 11111100 (5) (-4)
Sean Barker
positive, 0 if X is zero, and -1 if X is negative.
10
Sean Barker
11
Signed 1 127
128 64 192 255 Unsigned Danger Zone Danger Zone
Sean Barker
12
(credit: xkcd.com)
Sean Barker
13
float sum_elements(float a[], unsigned length) { int i; float result = 0; for (i = 0; i <= length - 1; i++) { result += a[i]; } return result; }
Sean Barker
14
s' exp' frac'
1 k = 8 or 11 23 or 52
Sean Barker
15
+∞' −∞' F0' +Denorm' +Normalized' −Denorm' −Normalized' +0' NaN' NaN'
5 10 15 Denormalized Normalized Infinity
6-bit values (3 exp, 2 frac)
0.5 1
Close-up (central values)
Sean Barker
16