Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sentence converter
#1
I'm going to make a symplistic program which converts sentences or letters or whatever into binary code.
How would i go about this?
i could individually make each charactor a variable, but that would would take AGES. And besides, i'm not quite sure on how to make more than one number string :-? :-?
So how would i make it so i don't have to individually make each charactor a variable?
thanks for the help once agan Smile
n my personal opinion, Max Payne™ is the BEST game ever made...
Reply
#2
DIM letters(97 TO 122) AS STRING
FOR i = 97 TO 122
letters(i) = CHR$(i)
NEXT i
That initializes an array with a range of 97-122, 97 being a, 98 being b, 99 being c, etc. all the way to 122, being z.
NOTE: This initalizes an arreay of LOWER CASE letters. Only.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#3
i suppose i dont understand. if you want to turn it into a character array (in c, you'd look no farther because, alas, that's all strings are) you can just say something like:

Code:
x$ = "Sentence goes here"
dim chararray (1 to len(x$) as integer
for a = 1 to len (x$)
  chararray (a) = asc (mid$(x$, a, 1))
next

mid gets a specific chunk of the string. you use it to get individual letters in this case. asc, in turn, takes a single character, and returns the ascii numeral for it. finally, just in case you dont know, dim lets you create an array, that is, a set of numerically identifiable variables.

if you want to learn how to convert things into binary just reply so.

edit: of course, you dont need to convert everything into an array variable, you can just take it one at a time

asc (mid$(mystring$, characterposition, 1))

and print out your binary that way.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#4
Thanks for the help the both of you.
n my personal opinion, Max Payne™ is the BEST game ever made...
Reply
#5
id love to know how to convert asc to binary, and binary to ascci.

it it hard?
url]http://qb45.think-new.com[/url]
Reply
#6
Do you mean a string character when you say ASCII? or just its number?

Anyhow, to convert a decimal number to binary, you just have to change from base 10 to base 2. Very elementary maths needed here:

Code:
FUNCTION Dec2Bin$(number%)
res$=""
WHILE number% <> 0
   rema%=number% MOD 2
   res$ = res$+LTRIM$(STR$(rema%))
   number%=number%\2
WEND
Dec2Bin$=res$
END FUNCTION

You can test it now...

Code:
PRINT Dec2Bin$(69)

To display a character's binary value just nest functions...

Code:
PRINT Dec2Bin$(ASC("A"))

Hope this is what you wanted Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
damn dude, very nice Smile thats exactly what i was looking for.
url]http://qb45.think-new.com[/url]
Reply
#8
I'm not really that smart, so what i was talking about is like this:
you type in whatever sentnce(input) and it prints it out in binary code.
for example;
"type a sentence and it'll come out in binary! " hi
0110100001101001

If you know what i'm getting at
n my personal opinion, Max Payne™ is the BEST game ever made...
Reply
#9
Just make a loop from i%= 1 to LEN(MyString$), and for each character MID$(MyString$, i%, 1) call my function and print the output.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)