Badly Needed! Bin2string

 BBS: Inland Empire Archive
Date: 03-13-93 (22:59)             Number: 299
From: JOHN GALLAS                  Refer#: NONE
  To: CALVIN FRENCH                 Recvd: NO  
Subj: Badly Needed! Bin2string       Conf: (2) Quik_Bas
CF>relatively FAST decimal 2 binary function, as well as a binary 2
CF>decimal function to go with it. The binary function needs to be
CF>put in a string ($), so that I can deal with it. I'm not just
CF>'too lazy' to write it, the fact is that I don't think I could

A while ago someone posted a program to do all kinds of convertions,
bin2int, bin2hex, int2bin, etc.  Unfortunatly, I don't have the authors
name who wrote this little beauty -- (If you're reading this Mr Author,
can you please reply so I can put your name with the file?) -- I hope it
helps!


DEFINT A-Z

DECLARE FUNCTION Bin2Hex$ (Bin$)
DECLARE FUNCTION Bin2Int% (Bin$)
DECLARE FUNCTION Hex2Bin$ (Hcs$)
DECLARE FUNCTION Hex2Int% (Hcs$)
DECLARE FUNCTION Int2Bin$ (Dec%)
DECLARE FUNCTION Int2Hex$ (Dec%)

DEFSNG A-Z
FUNCTION Bin2Hex$ (Bin$)

   Bin2Hex$ = Int2Hex$(Bin2Int%(Bin$))

END FUNCTION

FUNCTION Bin2Int% (Bin$)
   FOR y = LEN(Bin$) TO 1 STEP -1
      IF MID$(Bin$, y, 1) = "1" THEN ax% = ax% + (2 ^ z)
      z = z + 1
   NEXT
   Bin2Int% = ax%
END FUNCTION

FUNCTION Hex2Bin$ (Hcs$)
   Hcs$ = UCASE$(Hcs$)
   lc = LEN(Hcs$)
   FOR x = 1 TO lc
      SELECT CASE MID$(Hcs$, x, 1)
         CASE "0"
            Out$ = Out$ + "0000"
         CASE "1"
            Out$ = Out$ + "0001"
         CASE "2"
            Out$ = Out$ + "0010"
         CASE "3"
            Out$ = Out$ + "0011"
         CASE "4"
            Out$ = Out$ + "0100"
         CASE "5"
            Out$ = Out$ + "0101"
         CASE "6"
            Out$ = Out$ + "0110"
         CASE "7"
            Out$ = Out$ + "0111"
         CASE "8"
            Out$ = Out$ + "1000"
         CASE "9"
            Out$ = Out$ + "1001"
         CASE "A"
            Out$ = Out$ + "1010"
         CASE "B"
            Out$ = Out$ + "1011"
         CASE "C"
            Out$ = Out$ + "1100"
         CASE "D"
            Out$ = Out$ + "1101"
         CASE "E"
            Out$ = Out$ + "1110"
         CASE "F"
            Out$ = Out$ + "1111"
      END SELECT
   NEXT
   Hex2Bin$ = Out$
END FUNCTION

FUNCTION Hex2Int% (Hcs$)

   Hcs$ = UCASE$(Hcs$)
   Hex2Int% = Bin2Int%(Hex2Bin$(Hcs$))

END FUNCTION

FUNCTION Int2Bin$ (Dec%)
   tdec% = Dec%
   DO WHILE tdec% > 0
      IF tdec% / 2 = tdec% \ 2 THEN
         Bin$ = "0" + Bin$
      ELSEIF tdec% / 2 <> tdec% \ 2 THEN
         Bin$ = "1" + Bin$
      END IF
      tdec% = tdec% \ 2
   LOOP
   Int2Bin$ = Bin$
END FUNCTION

FUNCTION Int2Hex$ (Dec%)
   Int2Hex$ = HEX$(Dec%)
END FUNCTION

 * OLX 2.1 TD * *'M ST*P*D - I'd like to buy a vowel Pat, an 'O'

--- Maximus 2.01wb
 * Origin: Command Line BBS =Mpls. MN= V.32bis [612-788-6685] (1:282/2007)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET