I already done this but this only can accept number not letter. Which part that i need to change?

10-29-2011, 10:09 AM

pbrockway2

Re: convert 30 char of ascii to binary

Quote:

I already done this but this only can accept number not letter. Which part that i need to change?

To be more precise your program accepts a string from the user and uses this to create an integer number which it converts.

There is no reason why you could not just read() rather than readLine(). This would give you an int directly without the need to parse anything, and the result string can be built up as you are already doing.

Of course this would convert only a single character - so you would need to put the whole process inside a loop so that it is done 30 times.

-----

You should follow Java coding style and (1) indent the code, and (2) Start the variable holding the current bit value with a lower case letter: bit.

"result+=0" had me confused for a moment. It would be far more readable if the string containing a zero digit were written as a string to make it clear you mean to concatenate rather than increment.

Code:

result += "0";

"while(true){...}" is more readable to my eye than "do{...}while(true)" - but that may be just me. I like to see the important loop bits "upfront" and, so, prefer while and if to do.

10-29-2011, 10:15 AM

pbrockway2

Re: convert 30 char of ascii to binary

Quote:

I already done this

Is this your code? (Hint: I know the answer, but others here deserve to know as well.)

Please note that RoseIndia not a good site. You might do better to throw away what you have and start afresh with your own code.