SUBprogram to Convert Integer to a String in Binary Notation (43567)
The information in this article applies to:
- Microsoft QuickBASIC 3.0
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
This article was previously published under Q43567 SUMMARY
Below is a QuickBasic SUBprogram that converts an integer to binary
notation (represented in a string form). Both an integer and a string
variable are passed to the SUBprogram and the result is returned in
the string variable. The integer is broken down bit by bit and
converted into its hexadecimal equivalent.
This code will execute correctly in Microsoft QuickBasic Versions
3.00, 4.00, 4.00b, and 4.50, in Microsoft Basic Compiler Versions 6.00
and 6.00b, and in Microsoft Basic PDS Version 7.00.
The code example is as follows:
DEFINT A-Z
'__________________________________________________________________
'
' IntToBin() takes an INTEGER argument and produces a
' binary string representation of the INTEGER.
'__________________________________________________________________
'
SUB IntToBin (byte%, bin$) 'Add STATIC here to get SUB to
bin$ = "" 'work in QuickBasic 3.00
temp% = byte%
FOR i = 0 TO 7
IF temp% AND 1 THEN
bin$ = "1" + bin$
ELSE
bin$ = "0" + bin$
END IF
temp% = temp% \ 2
NEXT
END SUB
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | KB43567 |
---|
|