Tom Kelliher, CS18
Mar. 1, 1996
char, int
Attributes:
Note:
char[]
Memory allocation:

Signed, unsigned two's complement representation
Consider the eight bit number:
Signed value:
Unsigned value:
Examples:
Smallest, largest values for each representation?
How many unique values can be represented by n bits?
, proven by induction on n
Basis: n = 1
and a
one bit number has two unique values: 0 and 1.
Inductive Step: Assume that
bits can represent
values, show that k+1 bits can represent
values.
k+1 bit numbers can be broken into 2 groups:
0<k bits>
1<k bits>
Counting and using the inductive hypothesis, there are
k+1 bit numbers. QED.
Formulas for ranges of n-bit numbers?
Memory allocation:
float, double, long double

Precision:
Range:
Consider 4 bit signed/unsigned numbers
#include <iostream.h>
int main()
{
double little = 1.0E-10;
double middle = 1.0E4;
double big = 1.0E6;
double bigger = 1.0E7;
cout << (middle + little) - middle << endl;
cout << (big + little) - big << endl;
cout << (bigger + little) - bigger << endl;
return 0;
}
Output:
1.00044e-10 1.16415e-10 0
Expression types:
Relative ``sizes'' of types:
Note: range increasing
Assignment conversion to ``smaller'' type unsafe (?)
Given the declarations, determines the expression types and the ``safeness:''
int a; unsigned int b; char c; float x; double y; long double z; c = a % b - 5; x = c - b * a; b = c * c + b * a / 3; a = y - c * a % b; x = y * z; c = +x * -y + 7 / z; x = ((x - 6) * (x - 6) + y * y) / (z * z); x += c + z;