How to Obtain Upper and Lower Bytes of an Integer (27097)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q27097

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
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB27097