' Conversion from Base 10 to Base 2 ' Written by Michael L. Jones, M. S., Spring 2002 ' Suffolk County Community College, Brentwood, New York ' Plan of attack: Input a number in base 10. The compiler checks that the ' input is in fact a number. Divide the number by 2, keeping track of the ' remainder as a string. Keep dividing and accumulating remainders until ' you get a zero quotient. The remainders from last to first make up the ' base 2 number. CLS DEFLNG D 'Allows for large numbers INPUT "What is the decimal number"; decimal PRINT dec = decimal 'Keep a copy of decimal for final output bin$ = "" 'Initialize binary number WHILE dec > 0 rmdr = dec MOD 2 'Remainder of number divided by 2 'Set remainder to its string equivalent IF rmdr = 0 THEN digit$ = "0" IF rmdr = 1 THEN digit$ = "1" 'Append remainder character to front of binary number bin$ = digit$ + bin$ dec = INT(dec / 2) WEND PRINT "The binary equivalent of"; decimal; "is "; bin$; "." END