Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
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:
var a, b, c : byte; 
d : word;
...
a := 241;
b := 128;
c  := a + b;       
// equals 113
c  := word(a + b); 
// equals 113
d  := a + b;     
// equals 369
154
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5