Appendix C:
Basic Integer Variable Storage
Manual Number: 00650-014-4
Page C-1
Appendix C:
Basic Integer Variable Storage
Data are stored in integer variables (% type) in binary form. Each integer variable uses 16 bits or
two bytes of memory. Sixteen bits of binary data is equivalent to 0 to 65,535 decimal. Numbers
are represented as follows:
1XPEHU
+LJK%\WH
/RZ%\WH
%
%
%
% % % %
%
%
%
%
%
% % % %
Integer variables are the most compact form of storage for the 12-bit data from the A/D converter
and the 16-bit data from the interval timer. Therefore, to conserve memory and disk space and to
optimize execution time, all data exchange via the CALL is through integer type variables.
This poses a programming problem when handling unsigned numbers in the range 32,768 to 65,535.
If you wish to input or output an unsigned integer greater than 32,767, then it is necessary to work
out what its 2s complement signed equivalent is. For example, if 50,000 decimal is to be loaded
into a 16-bit counter, an easy way to convert this to binary is to enter BASIC and execute PRINT
HEX$(50000). This returns C350 which, in binary form is 1100 0011 0101 0000. Since the most
significant bit is a one, this would be stored as a negative integer and, in fact, the correct integer
variable value would be 50,000 - 65,536 = -15,536.
Thus, the programming steps to switch between integer and real variables for representation of
unsigned numbers between 0 and 65,535 is:
-From real variable N (where 0 <= N <= 65,535) to integer variable N%:
xxx10 IF N<=32767 THEN N% = N ELSE N% = N-65536
-From integer variable N% to real variable N:
xxx20 IF N% >= 0 THEN N=N% ELSE N = N%+65536