I am writing a method in which I convert int values to binary strings and store them. I use the Integer.toBinaryString method for this, and it works correctly, but the problem is that I need a method that returns exactly 4 bits per line, and not less (this will never be more, because the numbers are not big enough). Here is an example of my code and where the problem occurs:
int value5 = 3;
String strValue5 = Integer.toBinaryString(value5);
for(int index = 0; index < 4; index++){
sBoxPostPass[4][index] = strVal5.charAt(index);
}
Obviously, this will throw an ArrayOutOfBoundsException because strValue5 == 11, and not 0011, as it should be. Hope this is clear enough. Thank you in advance.
user1214845
source
share