Article ID: 38888
This article was previously published under Q38888
This article has been archived. It is offered "as is" and will no longer be updated.
This article concerns assigning a LONG integer to a hexadecimal constant in the range &H8000 through &HFFFF hex. This information is especially important if you intend to do any bit manipulation with the logical operators (AND, OR, NOT, XOR, EQV, or IMP) with any LONG integer larger than &HFFFF& hex (or 65,535 decimal) that has at least one bit from 16 through 32 on.
Many programmers may not realize that the constants &H8000 through &HFFFF default to a type of short integer, representing decimal values -32,768% through -1% respectively. Also note that the LONG-integer constants &H8000& through &HFFFF& represent decimal values +32,768 to +65,535. Basic must follow these integer-type notation standards and behaviors since it doesn't have an unsigned data type.
This information applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.
Assigning a LONG integer variable to a short integer hexadecimal constant in the range &H8000 through &HFFFF adds &HFFFF0000 to the number, resulting in the LONG integer being stored as &HFFFF8000 to &HFFFFFFFF (that is, -32,768& to -1& decimal).
This behavior occurs because constants &H8000 through &HFFFF default to a type of short integer (%). In short integer notation, constants &H8000 through &HFFFF have decimal values -32,768% through -1%, respectively. For example:
To assign hex constants &H8000 through &HFFFF to a LONG integer without turning on bits 16 through 32 (&HFFFF0000), you must change them to a type of LONG by appending an ampersand (&) character as follows:
Appending "&" to the constant is not necessary for hex constants outside the range &H8000& through &HFFFF&.
The LONG integer &HFFFF& hex is equal to 65,535 decimal. The short integer &HFFFF hex is equal to -1 decimal (according to the signed, two's complement, integer format standard). A -1 in decimal notation is &HFFFFFFFF in hex LONG-integer notation.
The hexadecimal constants &H8000 through &HFFFF default to short integers &H8000% through &HFFFF%, which represent the decimal numbers -32,768% to -1% in the two's complement, signed binary integer format. You must append an ampersand (&) character to the end of the constant to make it a LONG integer, as follows: &H8000& through &HFFFF& (which represent the decimal numbers 32,768 through 65,535).
The hexadecimal constants &HFFFF8000 to &HFFFFFFFF are LONG integers that represent the decimal numbers -32,768& to -1& in the two's complement, signed binary integer format.
Note: Bit masking (manipulation) is normally NOT done with floating-point numbers, because of the nature of the floating-point format. Bit masking normally is useful only with integers.
Code Example 1
Code Example 2
Article ID: 38888 - Last Review: February 27, 2014 - Revision: 1.2
Contact us for more help
Connect with Answer Desk for expert help.