I'm trying to save some data into an array but unfortunately all the data is saving into array[0] while it shouldn't be like this normally.
int j = 0;
while ( j < data.length ) {
float unbin = binary(data[2*j+1])+binary(data[2*j]);
float[] bin = new float[] {unbin};
print(bin);
j = j + 2;
}
it wrote all the data in bin[0] , what's wrong with my code ?
how could I write :
bin[j] = unbin ?
to save the data in in bin[0] while j = 0 and so on ?
here is the updated code :
int j = 0 ;
float[] bin1 = new float[(data.length/2)];
while (j < data.length ) {
if ( data[2*j+2] >= 0 ) {
String unhx =(binary(data[2*j+3])+binary(data[2*j+2])+binary(data[2*j+1])+binary(data[2*j]));
float unbin = ((float)unbinary(unhx)/100);
bin1[j/2] = unbin;
print(bin1[1]);
}
else if ( data[2*j+2] < 0 && data[2*j+3] < 0 ) {
data[2*j] = (byte)(-data[2*j]);
data[2*j+1] = (byte)(-data[2*j+1]);
String unhx =(binary(data[2*j+1])+binary(data[2*j]));
float unbin = ((-1)*(float)unbinary(unhx)/100);
bin1[j/2] = unbin;
print(bin1[1]);
}
j = j + 2;
}