User manual

219
mikoPascal PRO for dsPIC30/33 and PIC24
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 num-
ber 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 2
n
if all discarded bits are zero. This is also
true for signed operands if all discarded bits are equal to the sign bit.