47
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
In the above example, both x and c will contain the same binary data. However, c
is a signed 8-bit value, so binary contents of 254 mean -2. Strictly speaking, this
reinterpretation will only happen if the value of x exceeds maximum positive
number that c can hold -- 127. If x<=127 conversion will not cause
reinterpretation. For example, if x=15 then doing c=x will result in c=15 as well.
In fact, in some cases, conversion from unsigned type to a signed time will never
result in the reinterpretation. This is when the maximum value that the source
unsigned variable can hold can always fit in the range of positive values that the
signed destination variable can hold. Example: conversion from byte (value range
0-255) to short (value range -32768 to 32767) will never result in the
reinterpretation.
Conversion from signed type into unsigned type will always cause reinterpretation
if the source variable contained a negative value.
Conversions that cause truncation
Conversions marked with "
Truncate
" mean that part of the binary data (on the
most significant side) may be lost during the conversion. For example, converting
from word type into byte type will only leave 8 bits of the original 16-bit value:
dim
x
as
byte
dim
w
as
word
w = 12345
'hex representation of 12345 is 3039
x = w
' now x contains 57. Why? Because only '39' of '3039' could fit in,
and decimal of &h39 is 57.
Notice, that some conversions will cause reinterpretation and truncation at the
same time!
Conversions that round the number (remove fractions)
Conversions from real type into any other numerical type will cut off the fraction,
as real is the only type that can hold fractions. Such conversions are marked as "
Fraction
" in the table above.
Conversions that implicitly invoke functions available to the user
Some conversions automatically invoke functions (syscalls) available for use in
your program. In such cases the table above lists the name of the function
invoked. For example, conversion from byte into string relies on the
function. Two ways of conversion below produce identical result:
dim
x
as
byte
dim
s
as
string
s = str(x)
' explicit invocation
s = x
' implicit invocation. Compiler is smart enough to use str for this
conversion
Conversion of Boolean Variables
Boolean variables are actually stored as byte type variables; thus, all notes above
for byte type variables hold true for boolean variables as well.
207