
Binary Routines I've Written (Public Domain)
This is a multi-part message in MIME format.
------=_NextPart_000_01BCC373.D19CC9A0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
- See attachement "Bin$.bas"
But my routines in attachement "Bin$2.bas" are more than 20 times as fast!
Who can make them even faster?
Ewoud Dronkert
dronkert AT fys DOT ruu DOT nl
------=_NextPart_000_01BCC373.D19CC9A0
Content-Type: application/octet-stream; name="Bin$.bas"
Content-Transfer-Encoding: 7bit
Content-Description: Bin$.bas (Visual Basic Module)
Content-Disposition: attachment; filename="Bin$.bas"
DECLARE FUNCTION BIN$ (decimal&)
DECLARE FUNCTION bVAL& (binary$)
CLS
INPUT "Decimal number:", a&
PRINT BIN$(a&)
INPUT "Binary number:", b$
PRINT bVAL&(b$)
END
FUNCTION BIN$ (decimal&)
t$ = ""
FOR x% = 15 TO 0 STEP -1
IF (decimal& AND 2 ^ x%) = 2 ^ x% THEN
t$ = t$ + "1"
ELSE
t$ = t$ + "0"
END IF
NEXT
BIN$ = t$
END FUNCTION
FUNCTION bVAL& (binary$)
t& = 0
FOR x% = 1 TO LEN(binary$)
IF MID$(binary$, x%, 1) = "1" THEN
t& = t& OR 2 ^ (LEN(binary$) - x%)
END IF
NEXT
bVAL& = t&
END FUNCTION
------=_NextPart_000_01BCC373.D19CC9A0
Content-Type: application/octet-stream; name="BIN$2.BAS"
Content-Transfer-Encoding: 7bit
Content-Description: Bin$2.bas (Visual Basic Module)
Content-Disposition: attachment; filename="BIN$2.BAS"
DECLARE FUNCTION bVAL& (binary$)
DECLARE FUNCTION BIN$ (decimal&)
CLS
INPUT "Decimal number:", a&
PRINT BIN$(a&)
INPUT "Binary number:", b$
PRINT bVAL&(b$)
END
FUNCTION BIN$ (decimal&)
x& = decimal&
t$ = ""
DO
IF (x& MOD 2) <> 0 THEN
t$ = "1" + t$
ELSE
t$ = "0" + t$
END IF
x& = x& \ 2
LOOP UNTIL x& = 0
BIN$ = t$
END FUNCTION
FUNCTION bVAL& (binary$)
t& = 0
FOR i% = 1 TO LEN(binary$)
t& = t& * 2
IF MID$(binary$, i%, 1) = "1" THEN
t& = t& + 1
END IF
NEXT
bVAL& = t&
END FUNCTION
------=_NextPart_000_01BCC373.D19CC9A0--