Specifications
Section 4. CRBasic - Native Language Programming
4-9
Expressions are evaluated as integers for as long as possible
Public X, I AS Long
BeginProg
I = 126
X = (I+3) * 3.4
‘I+3 is evaluated as an integer,
‘then converted to FLOAT before
‘it is multiplied by 3.4
EndProg
Constants will be converted to Longs and/or Floats at compilation
If a constant (either entered as a number or declared with CONST) can be
expressed correctly as an integer, the compiler will use the type that is most
efficient in each expression. The integer version will be used if possible, i.e.,
if the expression has not yet confronted a float.
Public I AS Long, ‘I is an integer
Public F1, F2 ‘F1 and F2 are Floats
CONST ID = 10
BeginProg
I = ID * 5 ‘ID (10) and 5 are loaded at
‘compile time as Floats
F1 = F2 + ID ‘ID (10) is loaded at compile
‘time as a float to avoid a
‘run time conversion from an
‘integer before each addition
EndProg
4.5 Numerical Entries
In addition to entering regular base 10 numbers there are 3 additional ways to
represent numbers in a program: scientific notation, binary, and hexadecimal
(Table 4.5-1).
TABLE 4.5-1 Formats for Entering Numbers in CRBasic
Format Example Value
Standard 6.832 6.832
Scientific notation 5.67E-8 5.67X10
-8
Binary: &B1101 13
Hexadecimal &HFF 255
The binary format makes it easy to visualize operations where the ones and
zeros translate into specific commands. For example, a block of ports can be
set with a number, the binary form of which represents the status of the ports
(1= high, 0=low). To set ports 1, 3, 4, and 6 high and 2, 5, 7, and 8 low; the
number is &B00101101. The least significant bit is on the right and represents