TOPIC 4.1. DATA TYPES

DIFFERENT DATA TYPES

        (i) INTEGER (Whole numbers)

        (ii) REAL (Numbers with a decimal point)

        (iii) CHARACTER (any ASCII character such as letter, number or 'special character' like @, or #)

        (iv) BOOLEAN (A variable which can only hold the value true or false)

type Range Format
shortint -128 .. 127 signed 8-bit
integer -32768 .. 32767 signed 16-bit
longint -2147483648 .. 2147483647 signed 32-bit
byte 0 .. 255 unsigned 8-bit
word 0 .. 65535 unsigned 16-bit
var
    grade : char;
    mark1 : integer;
    mark2 : integer;
    average :real;

                student_name : string;

        which in Turbo Pascal allows up to 255 characters to be stored in student_name, using a statement such as

                student_name : 'Mary Jones';

RULES FOR IDENTIFIERS

The program name and the variable names are all called as identifiers, and the following rules apply:

ASSIGNMENT STATEMENTS

            daily_cost := cost_of_lunch + 2 * cost_of_drink;

Operator Operation Operand types Result type
+ addition integer type; real type integer type; real type
- subtraction integer type; real type integer type; real type
* multiplication integer type; real type integer type; real type
/ division integer type; real type real type; real type
div integer division integer type integer type
mod remainder integer type integer type

READING IN DATA FROM A KEYBOARD

            read (mark_1, mark_2, mark_3);

or

read (mark_1);
read (mark_2);
read (mark_3);

where mark_1, mark_2, mark_3 are integer values all typed on one line, separated by at least one space.

        read (mark_1);

        readln;

has the same effect as

        readln(mark_1);

 

DISPLAYING DATA ON THE SCREEN

            write('Average = ');

            writeln(average);

            has the same effect as

            writeln('Average = ', average);

 

FORMATTING OUTPUT

            writeln('Average = ', average: 5 :1);

            will print

            Average = 74.0 (leaving one space after the = sign, for  a total field width of 5).

COMPOUND STATEMENTS AND PUNCTUATION


CHARACTER CODES AND THEIR REPRESENTATION

Character ASCII
space 00100000
! 00100001
" 00100010
# 00100011
$ 00100100
% 00100101
& 00100110
` 00100111
( 00101000
) 00101001
* 00101010
+ 00101011
, 00101100
- 00101101
. 00101110
/ 00101111
0 00110000
1 00110001
2 00110010
3 00110011
4 00110100
5 00110101
6 00110110
7 00110111
8 00111000
9 00111001
: 00111010
; 00111011
< 00111100
= 00111101
> 00111110
? 00111111
@ 01000000
A 01000001
B 01000010
C 01000011
D 0100100
E 01000101
F 01000110
G 01000111
H 01001000
I 01001001
J 01001010
K 01001011
L 01001100
M 01001101
N 01001110
O 01001111
P 01010000
Q 01010001
R 01010010
S 01010011
T 01010100
U 01010101
V 01010110
W 01010111
X 01011000
Y 01011001
Z 01011010
[ 01011011
\ 01011100
] 01011101
^ 01011110
_ 01011111
' 01100000
a 01100001
b 01100010
c 01100011
d 01100100
e 01100101
f 01100110
g 01100111
h 01101000
i 01101001
j 01101010
k 01101011
l 01101100
m 01101101
n 01101110
o 01101111
p 01110000
q 01110001
r 01110010
s 01110011
t 01110100
u 01110101
v 01110110
w 01110111
x 01111000
y 01111001
z 01111010
{ 01111011
| 01111100
} 01111101
~ 01111110
del 01111111
Table 6.1: The ASCII character codes (excluding the extended character set)

REPRESENTATION OF INTEGERS

            3 X 100 + 8 X 10 + 7 X 1

TRANSLATING FROM BINARY TO DENARY

128 64 32 16 8 4 2 1
0 1 0 1 1 1 0 1

This represents 64 + 16 + 8 + 4 + 1

TRANSLATING FROM DENARY TO BINARY

Write the column headings 128 64 32 16 8 4 2 1
64 'fits' 0 1            
Subtract 64 from 105 leaving 41. 32 'fits' 0 1 1          
Subtract 32 from 41 leaving 9, and so on 0 1 1 0 1 0 0 1

 

BINARY ARITHMETIC

            0 1 1 0 1 0 1 1 + 0 0 0 1 1 0 1 1 = (DIY- Test your self)

REPRESENTING NEGATIVE NUMBERS USING SIGN AND MAGNITUDE

REPRESENTING NEGATIVE NUMBERS USING 2'S COMPLEMENT

        1. Find the binary value of the equivalent positive decimal number.

        2. Change all the 1s to 0s and vice versa.

        3. Add 1 to the result.

            1. Starting from the right, leave all the digits alone up to and including the first 1.

            2. Change all the other digits from 0 to 1 and 1 to 0.

THE HEXADECIMAL NUMBER SYSTEM

            0110 1111 1001 1100 = 6 F 9 C

THE OCTAL NUMBER SYSTEM

            001 101 111 = 1578


RESOURCES:

1) P M Heatcote & K R Bond, [A Level Computing], Letts Educational Ltd, 1999.

2) P M Heatcote, [A Level computing, 3rd Edition], Ashford Colour Press Ltd, 1996.

Hosted by www.Geocities.ws

1