Evan
Shane&Lisa wrote:
You have probably got this figured out already but I got thinking about it and couldn't stop until I figured it. There's probably more elegant solutions:
class test { public static void main(String [] args) { String str; int size; int index;
//an array to store integers instead of charicters int [ ] prims;
//the offending string of binary str = "0101010101010101010";
//the size of the string size = str.length();
//set our new array to the size prims = new int [size];
System.out.print("The length of the string is: " + size);
for (index = 0; index < size; index++) { //not the most elegant solution prims[index] = ((int) str.charAt(index) - 48);
//to make sure it's working properly System.out.print("\ngot number " + prims[index]); }
//now you have an array of integers! }
}
Evan Brown wrote:
Anyone ever use Java to go from big String of binary, break up the string into certain byte sizes and convert them to primative datatypes? If so how did you do it cuz my code is ugly and I need some help.
Evan Brown
