Computer Science Canada

ASCII to Binary?

Author:  mapleleaf31 [ Thu Jan 20, 2005 4:31 pm ]
Post subject:  ASCII to Binary?

So I need a code that converts from a sentence of characters into ASCII and into Binary displaying both on the screen, I have the ASCII part down but when I try and enter in a whole sentence I get an error

"Parameter to "ord" is not of length one"

How can I fix this and have them display one after the other?

Heres the code so far:

code:
var letter : string
var size : int

locatexy (50, 190)
put "Enter the letter"
get letter : *
size := length (letter)


for i : 1 .. size
    put ord (letter (i)) : 4 ..
    put intstr (ord (letter), 0, 2)
    put ""
    delay (1000)
end for

Author:  Cervantes [ Thu Jan 20, 2005 4:52 pm ]
Post subject: 

To fix the error, change
code:

put intstr (ord (letter), 0, 2)

to
code:

put intstr (ord (letter (i)), 0, 2)

Author:  eNc [ Thu Jan 20, 2005 4:54 pm ]
Post subject: 

still doesn't work, try entering y, it doesn't convert it to binary, it has a 2 in it which is not possible.

Author:  Cervantes [ Thu Jan 20, 2005 5:08 pm ]
Post subject: 

Comment out the first put line.

Author:  mapleleaf31 [ Thu Jan 20, 2005 6:25 pm ]
Post subject: 

what do you mean by try entering y?

I tried your first fix Cervantes and it didn't work like eNc said. I also commented out the first put line and that didn't work, same error.

It works if I only enter in 1 character but I need to be able to type in a whole sentence.


: