How to Obtain Upper and Lower Bytes of an Integer
ID: Q27097
The information in this article applies to:
- The Standard and Professional Editions of Microsoft Visual Basic
for MS-DOS, version 1.0
- Microsoft QuickBasic for MS-DOS, versions 4.0, 4.0b, and 4.1
- Microsoft Basic Compiler for MS-DOS and MS OS/2, versions 6.0 and
6.0b
- Microsoft Basic Professional Development System (PDS) for MS-DOS
and MS OS/2, version 7.0
SUMMARY
The program listed below demonstrates how to obtain the upper and lower
bytes of an integer. The following is sample code:
Example
' To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
CLS
a% = &HA0B0
ah% = (a% AND &HFF00) \ 256 AND &HFF ' Note: "\" means integer
division
al% = a% AND &HFF
PRINT HEX$(ah%) ' Prints high bytes: A0
PRINT HEX$(al%) ' Prints low bytes: B0
Additional reference words: VBmsdos QuickBas BasicCom
KBCategory: kbprg
KBSubcategory: