Fundamental Data Types and Conversions

Tom Kelliher, CS18

Mar. 1, 1996

Fundamental Data Types

Integer Types

char, int



Memory allocation:

Representation Ranges (Repeat)

Signed, unsigned two's complement representation

Consider the eight bit number:

Signed value:

Unsigned value:


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:

Counting and using the inductive hypothesis, there are k+1 bit numbers. QED.

Formulas for ranges of n-bit numbers?

Floating Point Types

Memory allocation:

float, double, long double



Common Runtime and Design Errors

Type Conversions

Expression types:

Relative ``sizes'' of types:

  1. signed int
  2. unsigned int
  3. signed long int
  4. unsigned long int
  5. float
  6. double
  7. long double

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;

Thomas P. Kelliher
Thu Feb 29 14:11:43 EST 1996
Tom Kelliher