Re: String of numbers into to array of numbers
bH wrote:
I accept all your criticism, revisions. I hope to
keep your model in front of me and try to correct the error
of my ways when I ask for "help" in this forum.
Lew's advice was very good, you should keep trying to write your
program. Your program was good too, it's useful to write programs that
are complete and run, it lets people make helpful comments on your code.
Two things occur to me here. First if you are going to write code, it's
good to make sure you understand the algorithm you need. I had no idea
how to do base 64 encoding or decoding, and I thought the explanation on
Wikipedia was very good. It cleared up all my misconceptions:
<http://en.wikipedia.org/wiki/Base64>
My second thought is very basic. Base 64 requires both an encoder and a
decoder. So, rather than try to deal with arrays of numbers, why not
just write the encoder first? That way you can have a program that will
make that silly array for you.
I don't have time to write code for you right now, but I think it should
look something like this:
public class Base64 {
public static String encode( String s ) {
}
public static String decode( String s ) {
}
public static void main( String ... args ) {
// First get the encoder working
String test = "My test string.";
String enc = encode( test );
System.out.println( "The encoded string is: " + enc );
}
}
Now you have the encoded string to feed to the decode method. Should be
much easier to write that method now. (Hint: don't forget that you can
call "getBytes()" or "toCharArray()" on any string to get an array of
numbers to work with.)
In software, it's often a good idea to write your test code first.