Help on a special array (2D) problem

I have a special array issue and so far I could not get it work properly. I hope someone of you has an idea and more experience.

Starting point:
I have a serial binding.
I receive a byte array (64 decimal numbers) via the serial and save it in an array: “byte[] array1D”

The decimal number (array) shall be converted to a binary of 8 digits.
Each binary digit shall be saved as an array element (2nd dimension) of the original array -> 1 dimension of array represents the position of the former decimal, 2nd dimension of array represents the binary element.
I will have a 2 D array with 64 lines and 8 rows.

How do I get from the 1 D array to the 2D array. I used "Integer::toBinaryString(array1D) to get the binaries from the string, but I do not know further now.

Thanx for any hints.

Cheers, cal

The Rules DSL does not support arrays very well. Behind the scenes it will convert an array to an ArrayList object which is one dimensional. You will need to create an ArrayList of ArrayLists and put your two Items into the one ArrayList.

Perhaps if you posted your code I could provide more concrete advice.

Dear rlkoshak,

thanx for your advice.

My code so far looks like that:

var byte[] ausgadr = cc2.state.toString.getBytes()
while ((i=i+1) < 65) {
var ausgStr = String::format("%s", Integer::toBinaryString(ausgadr.get(i)))

    var ausgStrn = Integer::parseInt(ausgStr)
    var ausgStr2 = String::format("%1$08d", ausgStrn)
    //var String[][] ausgstringArray = new newArrayOfSize(64,8)
    var ausgstringArray = ausgStr2.split("")
    var text1 = ausgstringArray.get(1)
    println("Eingangsdaten" + ausgadr.get(i))
    println("BinaryString" + ausgStr)
    println("BinaryInt " + ausgStr2)
    println("Binaryformatted1" + text1)

So if your values are always right next to each other, why do you need to go through the extra pain of creating a 2D array?

Just use a 1D array and the even indices are value 1 and the odd are value 2.

As far as I can tell “var ausgStr = String::format(”%s", Integer::toBinaryString(ausgadr.get(i)))isn't doing anything. toBinaryString already returns a String and %s doesn't do anything to the String sovar augStr = Integer::toBinaryString(ausgadr.get(1))` will give you the same thing.

Ok, the idea was the following.
Each decimal number stands for the state of a relais with 8 ports.
Translating the decimal to binary gives me the stae of each of the eight ports.

I thought I could easily read the sate of a port by addrssing it in a 2D array.