## BYTE

1. What are the values of each of the following operations? Write the resultant output in your exercise books:
 +37 17 shl 2 sqr(7) 71 div 3 succ (73) 71 mod 3 ord(19) 21 *3 abs(-123) 16/4 sqrt(4) pred(1) not 56 16 and 32 11 xor 3) 23 shr 2

2. Given the following declararions:

Var a, b, c : byte;

Determine the values that will be output for each of the variables and then explain it.

1. begin
a:=3 ;
b:=17;
c:=b-a;
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
end
2. begin
a:=8 ;
b:=13;
b:=9;
c:=b+a;
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
end
3. begin
a:=17;
b:=1;
c:=16 shr 1;
b:=3;
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
end
4. begin
a:=6 ;
b:=sqr(a);
c:=b mod a;
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
end
5. begin
a:=3 ;
b:= 9;
c:=5;
c:= c+sqr(a);
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + inttostr(c))
end

## CHAR

1. Determine the value of each of the following expressions. You may need to have a copy of the ASCII collating sequence handy.
 chr(77) upcase('*') ^j integer('E') ord('S') succ('Z') byte('A') pred('A') upcase('m') boolean(^A) 'x'<>'X' ord(#32) 'd'=#100 ord(^L) #25<=^Y

2. Given the declarations

```
var
a,b:	byte;
c:	char;
```

determine the values outputted for each of these variables after the following sequences of assignments.

1. begin
a:= 70;
b:= 9;
c:= chr(a+b);
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
end.
2. begin
b:= 3;
a:= 69;
c:='M';
c:= chr(a-b);
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
end.
3. begin
c:= 'h';
b:= 15;
a:= ord(c);
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
end.
4. begin
c:= '1';
a:= ord(c);
c:= succ(c);
b:= ord(c);
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
end.
5. begin c:= '3';
b:= ord(c);
c:= chr(b);
a:= 7+b;
showmessage('a= ' + inttostr(a) + ' b= ' + inttostr(b) + ' c=' + c)
end.

## BOOLEAN

1. What is the value of each of the following operations?

 true and true pred (true) true or false ord (true) false xor false false < = true false and true true > = false true xor false false <= false false or false true <> false ord (false) false < true succ (false) false = false

## INTEGER

1. What is the value of

 \$ABAB shr 3 ord (9155) lo (\$FACE) \$60FF xor \$7905 385 div 71 swap (\$ABCD) 193 and 2076 385 mod 71 lo (300) maxint or 5000 not maxint hi (745) abs (-42 1) hi (\$3000) swap (1 2 3)

2. Despite the fact that, i has been properly declared as an integer variable, each of the following statements will cause problems. Describe what type of error has been made in each, decide whether the compiler will spot it or whether it will be an error at runtime.

1. sqr(i)
2. i := sqrt(3)
3. i : = 3.5
4. i := 250*300
5. i := 307 div 0
6. i+l := 41*3
7. sqr(i) := 16

## REAL

1. Determine the values of each of the following:

 abs (-1.93) In (42.8) int (32.84) arctan (1.0) sqr (-1.4) exp (1.0) sqrt (36.0) sin (1.0) frac (18.83) 7.8*-6.1 trunc (231.4) 3.7-5.2 round (-82.7) 6.4/8.0 trunc (-5.5) 3.1 > 9.2 cos (1.22) 21.5 <= -21.5

2. Assuming that both r and s are legally declared real variables, that i is of type integer and that p is a boolean variable, what is wrong with each of the following assignment sequences?

1. begin
r:= 3.0;
s:=r-r;
r:= r/s
end.
2. begin
r :=-3.1;
i:= int(r);
s:= -r
end.
3. begin
s:= 12.0;
r:= frac(s);
s:= s/r
end.
4. begin r:= 3.0; s:= sqrt(9.0); p:= r=s end.

## TYPE CONVERSION

1. Express the following using conversions.

1. the character with ASCII number 98.
2. the ASCII number of the character 'k', as a byte.
3. the real number which corresponds to 71.
4. the byte corresponding to the Integer 23.
5. the integer which corresponds to the ASCII number of -L.
6. the integer which is as close as possible to 123.98.
7. the character which corresponds to the integer 50.
8. the integer which is equivalent to the byte value 18.

2. Assuming b is byte, c is char, p is boolean, i is integer and r is real, what is wrong with each of the following assignment statements?

1. i:= sqrt(3)
2. 9:= b
3. p:= odd(true)
4. i:= frac(9.0)
5. b:= trunc(maxint)
6. i:= odd(97)
7. 72:= trunc(72.9)
8. 7<3:= true
9. p:= not 21
10. r:= real(10)
11. p:= sqr(2)=sqrt(16)

## EVALUATING EXPRESSIONS

1. What is the value of each of the following expressions?

1. 10-5+3
2. 10-5*3
3. 10-5-3
4. 29 div 5 mod 3
5. 29 mod 5 div 3
6. 25 div 9 mod 3 * 2
7. abs (17 mod 13)
8. sqr (17 div 3)
9. abs (sqr(l1 mod 3) - sqr(l1 div 3))
10. pred (ord (succ (7))
11. pred (pred (pred ('M'))
12. ord (succ (chr (pred(86))))
13. abs(43) abs(27.4)
14. sqr(7.0) sqrt(81.0)
15. succ (sqr (8))
16. pred (trunc (int (-11.83)))
17. sqr (ord (pred ('B'))
18. odd (succ (ord ('R'))
19. trunc (abs (-1.0*13.7))
20. 6+3=2+7
21. (6>5) and (4>3)
22. (6>5) or (3>4)
23. (6>5) and (3>4)
24. '6' < 'D'
25. not (6 > 3)
26. (2=1) or not (3=4)
27. not (8<9) and ('v'<'V')
28. not ((8<9) and ('v'<'V'))
29. (7 < 6) and true
30. false or not false
31. false and not false
32. not (not (2 > 3) and not false)

2. Given the declared store

```	Var	i	:	integer;
c	:	char;
p,q	:	boolean;
r	:	real;
Begin
i:= 10;
c := 'S';
p := true;
q := false;
r := 4.5;
```

determine the value of the following boolean expressions:

1. i >= 10
2. p and not q
3. i > trunc(r)
4. not p and q
5. ord(c) < ord('T')
6. not p and not q
7. i*r > 100.0
8. not (p and q)
9. p and q
10. not p or not q
11. not (p or q)
12. not (i>5) and not (p and (c='S'))

3. Find an expression which will convert:

1. any uppercase letter into the corresponding lowercase letter.
2. any lowerease letter into the corresponding uppercase letter.
3. any uppercase letter into the corresponding control character.

4. The printing characters (commencing with the space) start at character number 32 and end with character number 126. The center letter in this sequence of characters has number 79. To save you looking this up, it is the capital letter '0'. To encode a message, you take each letter or character of the message and replace it with the character which is as far from 'O' as the character but on the other side. In other words, you draw a line through 'O' and mirror each character in this line.

1. Create an expression which converts any printing character into its coded character.
2. To complete this secret message business, you will also need a decoder. Write the decoding expression.

wonko@wonko.info