Qbasicnews.com

Full Version: Binary... Say what?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Make a qbasic program that convert words/ letters into binary.
I should be able to enter Joe and it comes out:

J = 00001010
O = 00001111
E = 00000101


Oh... and also... ABC = 123
So "J" = 10

Have fun!

Also... I have one that works... It's not perfect though.
BTW: No LIBs

EDIT: If you need help or don't know what binary is... PM me and ill explain it best as i can
Here's my one:

Code:
DECLARE FUNCTION Dec2Bin$ (Dec%)
DECLARE FUNCTION Word2Bin$ (Word$)

PRINT Word2Bin$("Hello")

FUNCTION Dec2Bin$ (Dec%)
Bin$ = ""
DO
  Bin$ = LTRIM$(STR$(Dec% MOD 2)) + Bin$
  Dec% = INT(Dec% / 2)
  IF Dec% = 0 THEN EXIT DO
LOOP
IF LEN(Bin$) < 8 THEN Bin$ = STRING$(8 - LEN(Bin$), "0") + Bin$
Dec2Bin$ = Bin$
END FUNCTION

FUNCTION Word2Bin$ (Word$)
Bin$ = ""
FOR n% = 1 TO LEN(Word$)
  Bin$ = Bin$ + Dec2Bin$(ASC(MID$(Word$, n%, 1)) - 64)
NEXT n%
Word2Bin$ = Bin$
END FUNCTION

It's a 3-Minutes-Work
I think I may have my old program somewhere..... nope, I guess I must have deleted it. It would change .txt files into hex or binary. Quite cool. sorry I couldn't find it.
ak00ma... Nice but not what i asked for...
This one maybe:

Code:
DECLARE FUNCTION Dec2Bin$ (Dec%)
DECLARE Sub Word2Bin (Word$)

Input Word$
Word2Bin(Word$)

FUNCTION Dec2Bin$ (Dec%)
Bin$ = ""
DO
  Bin$ = LTRIM$(STR$(Dec% MOD 2)) + Bin$
  Dec% = INT(Dec% / 2)
  IF Dec% = 0 THEN EXIT DO
LOOP
IF LEN(Bin$) < 8 THEN Bin$ = STRING$(8 - LEN(Bin$), "0") + Bin$
Dec2Bin$ = Bin$
END FUNCTION

SUB Word2Bin (Word$)
Bin$ = ""
FOR n% = 1 TO LEN(Word$)
  PRINT MID$(Word$, n%, 1) + "=" + Dec2Bin$(ASC(MID$(Word$, n%, 1)) - 64)
NEXT n%
END SUB
Even closer... but I want to inout a word... and also...

I want to be able to unout Joe
and it prints out

J = 00001010
O = 00001111
E = 00000101

Your missing something
Code:
input word$
print "J = 00001010"
print "O = 00001111"
print "E = 00000101"

:rotfl:

i think the goal of this program have been done time and again.

Code:
input word$
for y% = 1 to len(word$)
  value% = asc(mid$(word$, y%, 1))
  binary$ = ""
  for x% = 0 to 7
    if value% and 1 then binary$ = "1" + binary$ else binary$ = "0" + binary$
    value% = value% \ 2
  next x%
  print ucase$(MID$(word$, y%, 1)); " = "; binary$
next y%
toonski84: Not quite... Didn't print out the letter.

ak00ma: Yours didn't print out the CAPITAL letter
printed it out for me...

edit: oh, you want the capital letter? (anal-retentive bastard...) :lol:
edit: there... you have your capital letter! now be happy! *throws a screaming fit!*
What... you didn't pay attention
Pages: 1 2