# CONVERSION FUNCTIONS

``` BBS: Inland Empire Archive
Date: 10-07-92 (23:48)             Number: 263
From: DEREK LYONS                  Refer#: NONE
To: ALL                           Recvd: NO
Subj: CONVERSION FUNCTIONS           Conf: (2) Quik_Bas```
```Some interesting conversion functions:

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

* MegaMail 2.10 #0:Heads I win, Tails you lose.

--- WM v2.04/91-0077
* Origin: The Boardwalk! - (206) 941-3124 - Federal Way, WA (1:343/47)
``` 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