# simple question ?

Hi dear.

I need in this code

``````int pin = 7;
int duration[17];
byte sens[17];
byte cm[8];

void setup() {
Serial.begin(115200);
pinMode(pin, INPUT);
}

void loop() {

Serial.println("  ");
Serial.println("  ");
for (int i=0 ; i<17; i++){

duration[i] = pulseIn(pin, HIGH);

if(duration[i]<100 ) {sens[i]=0;}
else if(duration[i]<250 & duration[i]> 200  ) {sens[i]=1;}
else { sens[i]=1000; }

}

cm[0]=sens[9];
cm[1]=sens[10];
cm[2]=sens[11];
cm[3]=sens[12];
cm[4]=sens[13];
cm[5]=sens[14];
cm[6]=sens[15];
cm[7]=sens[16];

}
``````

cm array is accouring 10101010010 so some binary. I need in cm’s all things put to sideby side in one variable not array.

For ex.

int cm[4]=(1,0,1,1)

how can I pull this things from cm array to a variable for ex

a=1011;

If I can do that I turn the a into Decimal.

Thank you

``````int cm[4] = { 1,0,1,1 };
int value = 0;

value += cm[3] * 1;
value += cm[2] * 2;
value += cm[1] * 4;
value += cm[0] * 8;
``````

You can turn this into more efficient code by using a for() loop that keeps doubling the multiplication value.

``````const byte pin = 7;

void setup() {
Serial.begin(115200);
pinMode(pin, INPUT);
}

void loop() {
Serial.println("  ");
unsigned long a = 0;
for (int i = 0 ; i < 17; i++)
{
if (i >= 9 && i <= 16)
{
a *= 10;  // For decimal.  (Use *= 2 for binary)
if (pulseIn(pin, HIGH) > 200)
a += 1;
}
}

Serial.print("Value of 'a' is ");
Serial.println(a);
}
``````