How to convert decimal to binary.


The following are three examples of converting decimal to binary. (with a range of 0 to 255)
Someone's code:


zbin$="00000000"
FOR x = 0 TO 7
IF (n AND 2^x) THEN MID$(zbin$,(x XOR 7) + 1, 1) = "1"
NEXT x
PRINT zbin$

Agamemnus's code:

n = 252
m$ = "00000000"
FOR i = 0 TO 7
IF n AND 1 THEN MID$(m$, 8 - i, 1) = "1" ELSE MID$(m$, 8 - i, 1) = "0"
n = n \ 2
NEXT i
PRINT m$

Moneo's code:

DIM bin AS LONG
bin = 0
FOR x = 0 TO 7
IF (n AND 2^x) THEN bin = bin + 10^x
NEXT x
PRINT RIGHT$("00000000" + LTRIM$(STR$(bin)), 8)


DecimalToBinary - page last edited 2004-01-19 06:50:37 by 172.131.255.43 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster