User manual

218
mikoPascal PRO for PIC32
MikroElektronika
Unsigned and Conversions
If a number is converted from less complex to more complex data type, the upper bytes are lled with zeroes. If a
number is converted from more complex to less complex data type, the data is simply truncated (the upper bytes are
lost).
For example:
var a : byte; b : word;
...
a := $AA;
b := $F0F0;
b := b and a;
{ a is extended with zeroes; b becomes $00A0 }
Signed and Conversions
If number is converted from less complex to more complex data type, the upper bytes are lled with ones if sign bit is
1 (number is negative); the upper bytes are lled with zeroes if sign bit is 0 (number is positive). If number is converted
from more complex to less complex data type, the data is simply truncated (the upper bytes are lost).
For example:
var a : byte; b : word;
...
a := -12;
b := $70FF;
b := b and a;
{ a is sign extended, with the upper byte equal to $FF;
b becomes $70F4 }
Bitwise Shift Operators
Binary operators shl and shr move the bits of the left operand by a number of positions specied by the right operand,
to the left or right, respectively. Right operand has to be positive and less than 255.
With shift left (shl), left most bits are discarded, and “new” bits on the right are assigned zeroes. Thus, shifting
unsigned operand to the left by n positions is equivalent to multiplying it by 2n if all discarded bits are zero. This is also
true for signed operands if all discarded bits are equal to the sign bit.
With shift right (shr), right most bits are discarded, and the “freed” bits on the left are assigned zeroes (in case of
unsigned operand) or the value of the sign bit (in case of signed operand). Shifting operand to the right by n positions
is equivalent to dividing it by 2
n
.