# how can i change binary viraibles to vertical?

for example i have these virables:
byte temp[8];

temp[0]=B10101010;
temp[1]=B10101010;
temp[2]=B10101010;
temp[3]=B10101010;
temp[4]=B10101010;
temp[5]=B10101010;
temp[6]=B10101010;
temp[7]=B10101010;

now i want temp_2 variables to have the contest like that

byte temp2[8];
temp[0]=B11111111; //first bit of temp[0],first bit of temp[1],first bit of temp[2],first bit of temp[3],first bit of temp[4],first bit of temp[5],first bit of temp[6],first bit of temp[7],
temp[1]=B00000000;//second bit of temp[0],second bit of temp[1],second bit of temp[2],second bit of temp[3],second bit of temp[4],second bit of temp[5],second bit of temp[6],second bit of temp[7],
temp[2]=B11111111; // and so on...
temp[3]=B00000000;
temp[4]=B11111111;
temp[5]=B00000000;
temp[6]=B11111111;
temp[7]=B00000000;

any help?

Look at the bitRead and bitWrite functions. A for loop to read bit 0 from each of 8 positions in one array and write that bit to a single position in the other array would be possible.

thanks alot. i didnt know this function
here is my complete code for this convert

``````void setup() {

Serial.begin(9600);

}

void loop() {
byte temp[8]; //the input data
byte temp2[8]; //just a temp
byte temp3[8]; //the output data

temp[0]=B11101010;  //input data here
temp[1]=B10101011;
temp[2]=B10101010;
temp[3]=B10101010;
temp[4]=B10101010;
temp[5]=B10101010;
temp[6]=B10101011;
temp[7]=B11101010;

for (int i=0;i<8;i++){  //transfering bits one by one to temp3 using temp2
for (int j=0;j<8;j++){
}
temp3[i]=temp2[0] | (temp2[1] << 1) | (temp2[2] << 2) | (temp2[3] << 3) | (temp2[4] << 4) | (temp2[5] << 5) | (temp2[6] << 6) | (temp2[7] << 7);
}

for (int i=0;i<8;i++){ //just moving the data back to input data temp[8]
temp[i]=temp3[7-i];
}

for (int i=0;i<8;i++){ //printing the converted data
Serial.println(temp[i],BIN);
}
while(1) { }

}
``````

More succinct:

``````for (int i=0;i<8;i++){
temp3[i] = 0;
for (int j=0;j<8;j++){