Apr 23, 2002 #1 Guest_imported New member Jan 1, 1970 0 Is there any qbasic program which convert decimal numbers to binary? Thanks
Apr 23, 2002 #2 trollacious Programmer Sep 29, 2004 4,046 US This should do it for you: FUNCTION Dec2Bin$(onenumber AS INTEGER) DIM binstring AS STRING DIM onedigit AS INTEGER, decnumber AS INTEGER decnumber = onenumber binstring = "" DO onedigit = decnumber MOD 2 binstring = STR$(onedigit) + binstring decnumber = decnumber \ 2 LOOP WHILE decnumber > 0 Dec2Bin$ = binstring END FUNCTION Upvote 0 Downvote
This should do it for you: FUNCTION Dec2Bin$(onenumber AS INTEGER) DIM binstring AS STRING DIM onedigit AS INTEGER, decnumber AS INTEGER decnumber = onenumber binstring = "" DO onedigit = decnumber MOD 2 binstring = STR$(onedigit) + binstring decnumber = decnumber \ 2 LOOP WHILE decnumber > 0 Dec2Bin$ = binstring END FUNCTION