Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Clipping
In assignments and statements that require an expression of particular type, desti-
nation will store the correct value only if it can properly represent the result of
expression, i.e. if the result fits in destination range.
If expression evaluates to more complex type than expected excess data will be
simply clipped (the higher bytes are lost).
dim as byte
dim 
as 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 
float
) ahead of the expression to be con-
verted. The expression must be enclosed in parentheses. Explicit conversion can be
performed only on the operand left of the assignment operator.
Special case is the conversion between signed and unsigned types. Explicit conver-
sion between signed and unsigned data does not change binary representation of
data — it merely allows copying of source to destination.
For example:
dim as byte
dim 
as 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 cannot execute explicit conversion on the operand left of the assignment operator:
word(b) = a  ' Compiler will report an error
144
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5