User manual
212
mikoPascal PRO for PIC32
MikroElektronika
Clipping
In assignments and statements that require an expression of particular type, destination will store the correct value only
if it can properly represent the result of expression, i.e. if the result ts in destination range.
If expression evaluates to a more complex type than expected, excess of data will be simply clipped (higher bytes are
lost).
var i : byte; j : word;
//...
j := $FF0F;
i := j; // i becomes $0F, higher byte $FF is lost
Explicit Conversion
Explicit conversion can be executed at any point by inserting type keyword (byte, word, short, integer, longint or real)
ahead of an expression to be converted. The expression must be enclosed in parentheses. Explicit conversion can be
performed only on the operand right of the assignment operator.
Special case is conversion between signed and unsigned types. Explicit conversion between signed and unsigned data
does not change binary representation of data — it merely allows copying of source to destination.
For example:
var a : byte; b : short;
...
b := -1;
a := byte(b); // a is 255, not 1
// This is because binary representation remains
// 11111111; it's just interpreted differently now
You can’t execute explicit conversion on the operand left of the assignment operator:
word(b) := a; // Compiler will report an error
Conversions Examples
Here is an example of conversion:
program test;
type TBytePtr = ^byte;
var arr: array[10] of word;
ptr : TBytePtr;
var a, b, cc : byte;
dd : word;