Hi, thanks for looking at this thread. :)
The goal:
I have this 2D boolean array (from my decoder thread). I managed to write a method that goes through the rows and appends a '1' or a '0' to a string based on what's in the array (1 for true, 0 for false).
The problem:
I get a string containing what I need - but how do I covert a String "0101" to an int 5?
I've tried parsing, casting and myString.getByte(); (and googling :) ).
I assume myString.getByte(); gets me close to the goal, however I can't seem to make that last step.
The code:
public String stringBin(boolean[][] table, int row, int col) {
String bin = null; // declare & initialize String
for (int i = red; i <= row; i++) { // locate row
for (int j = 0; j < col; j++) { // go cell by cell till end of column
if (table[i][j] == false) {
bin += '0'; // add 0 for false
} else {
bin += '1'; // add 1 for true
}
}
}
bin = bin.substring(4); // bin contains "null", so cut that off
return bin;
}