Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  BASIC uses four data formats: integers, variable-length strings, and
  floating-point numbers in long and short form (known in BASIC terminology
  as single-precision and double-precision numbers). BASIC variables can be
  explicitly given one of these four format types by appending an
  identifying suffix to the variable name: % for integer, $ for string, !
  for single-precision (short floating point), and # for double-precision
  (long floating point). Numeric constants can be similarly classified.
  Implicit typing can be controlled with the DEF statement and defaults to
  single-precision. For reference, here are some simple examples:

  A%      Integer variable
  A!      Single-precision variable
  A#      Double-precision variable
  A$      String variable
  1%      Integer constant
  1!      Single-precision constant
  1#      Double-precision constant
  "1"     String constant

  Interpreted BASIC supports one integer data format: 2-byte (16-bit)
  integers. See page 23 for a general discussion of this data format.

  The distinction between signed and unsigned integers in BASIC is a bit
  blurry. BASIC regards integers as signed when it performs arithmetic,
  compares integers, or displays them with the PRINT statement. However,
  BASIC disregards the sign when it performs bitwise logical operations
  (AND, OR, XOR, and so on) and when processing hexadecimal values (values
  prefixed with &H or converted with the HEX$ function.)

  If you want to display unsigned decimal integers, convert them to
  floating-point:

  IF I%%@AE@% < 0 THEN D# = I%%@AE@% + 65536# ELSE D# = I%%@AE@%%@NL@%

  where I%%@AE@% is an integer and D# is its equivalent in double-precision. To
  convert values from double-precision to unsigned integers, you can use
  this method:

  IF D# > 32767 THEN I%%@AE@% = D# - 65536 ELSE I%%@AE@% = D#

  In interpreted BASIC, single-precision floating-point numbers are 4 bytes
  in size; double-precision values are 8 bytes. However, BASIC stores
  floating-point values in its own peculiar format. Not only is interpreted
  BASIC's floating-point format different from that used by most other
  programming languages for the PC family, it is also incompatible with the
  formats used by the 8087 and 80287 math coprocessors.

  String values in interpreted BASIC are stored in two parts: a string
  descriptor that holds the length and address of the string; and the string
  itself, which is a series of ASCII characters. (See Figure 20-1.)

  The string descriptor is 3 bytes long. The first byte contains the string
  length, which limits the maximum size of a string to 255 bytes. The next 2
  bytes are the near address of the actual string data. String data has no
  special format; it is simply stored as a series of bytes at the indicated
  address.

    String descriptor
  +-------------------+        +-----------------------------------+
  |String|  String    |        |H |e |l |l |o |, |  |W |o |r |l |d |
  |length|  address   |        +.----------------------------------+
  +-------------------+         |
               +----------------+

  Figure 20-1.  String data representation in interpreted BASIC.

  When the VARPTR function is applied to a string, it returns the address of
  the string descriptor. From the string descriptor, you can obtain the
  offset address of the string itself. The following program demonstrates
  the process of finding and decoding this information:

  100 INPUT "Enter any string: ",OUR.STRING$
  110 DESCRIPTOR.ADDRESS = VARPTR (OUR.STRING$)
  120 PRINT "The string pointer is at hex ";
  130 PRINT HEX$ (DESCRIPTOR.ADDRESS)
  140 STRING.LENGTH = PEEK (DESCRIPTOR.ADDRESS)
  150 PRINT "The length of the string is";
  160 PRINT STRING.LENGTH
  170 STRING.ADDRESS = PEEK (DESCRIPTOR.ADDRESS + 1)
      + 256 * PEEK (DESCRIPTOR.ADDRESS + 2)
  180 PRINT "The string value is at hex ";
  190 PRINT HEX$ (STRING.ADDRESS)
  200 PRINT "The string value is: ";
  210 FOR I = 0 TO STRING.LENGTH - 1
  220   PRINT CHR$ (PEEK (I + STRING.ADDRESS));
  230 NEXT I
  240 PRINT : PRINT
  250 GOTO 100

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson