Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal to Binary Converter

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there any qbasic program which convert decimal numbers to binary?
Thanks
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top