How can i merge 8 variables to 1;


hi , nice meet you
first of sorry bad english
secondly hopw can me problem.

i need merge 8 bits 1 varaible.
for example.
i have "temp" variables each 1 stores 1 or 0 digitalreading arduino pins:

int temp[7];
byte mybinary;

temp[0] = digitalread(pin1); //1 example
temp[1] = digitalread(pin2); //0 example
temp[2] = digitalread(pin3); //1 example
temp[3] = digitalread(pin4); //0 example
temp[4] = digitalread(pin5); //1 example
temp[5] = digitalread(pin6); //0 example
temp[6] = digitalread(pin7); //1 example
temp[7] = digitalread(pin8); //0 example


how can merge these values (from temp) "mybinary" variable;

all want "mybinary" variable  store "10101010" value this

mybinary=10101010 or mybinary=b10101010

i tried mybinary=temp[0] & temp[1] &..... &temp[7] didtnt work
:(


please me

try mybinary=temp[0] | (temp[1] << 1) | (temp[2] << 2) | (temp[3] << 3)  and on 7


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > How can i merge 8 variables to 1;


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums