Microsoft KB Archive/43567

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 16:56, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


SUBprogram to Convert Integer to a String in Binary Notation

Article ID: 43567

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 3.0
  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS



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
                


Additional query words: QuickBas BasicCom

Keywords: KB43567