Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
221
Signed and Conversions
If number is converted from less complex to more complex data type, the upper bytes are filled with ones if sign bit is 
1 (number is negative); the upper bytes are filled 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:
dim a as byte
dim b as word
‘ ...
  a = -12
  b = $70FF
  b = b and a
  ‘ a is sign extended, upper byte is $FF;
  ‘ b becomes $70F4
Bitwise Shift Operators
The binary operators 
<< 
and
  >>
 move the bits of the left operand by a number of positions specified by the right 
operand, to the left or right, respectively. Right operand has to be positive and less than 255.
With shift left (
<<
), 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.
With shift right (
>>
), 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
.
Boolean Operators
Although mikroBasic PRO for dsPIC30/33 and PIC24 does not support 
boolean
 type, you have Boolean operators at 
your disposal for building complex conditional expressions. These operators conform to standard Boolean logic, and 
return either 
TRUE
 (all ones) or 
FALSE
 (zero):
Operator
Operation
and
logical AND
or
logical OR
xor
logical exclusive OR (XOR)
not
logical negation
Boolean operators associate from left to right. Negation operator 
not
 associates from right to left.