Unable to convert array into Integer

My project consist of receiving binary in the form of array, and then converting the binary into an integer.

but their seems too be a problem in converting the array into an integer, i can seem to identify the problem.

example binary are 00001010 and 10001010, based on this two the 00001010 is able to convert while the others arent.

this is my caculation.

int bits[8];
int size = sizeof(bits)/sizeof(bits[0]);
int number = 0;
int val = 0;
int n = 0;

while(n < size)
{
val = bits[n];
if(val != 0){
number = number10;
number = number + 1;
}else{
number = number
10;
}
n++;
}

Serial.print("interger -- ");

Serial.println(number);

the attachment are the results

error.JPG

Your image:
error.JPG
Are you sure you have posted the same code that produced that serial print?

An int data type can not contain a number as large as 10000000, which is what you're asking it to do. You must use the 'long' data type.

May I ask, what use you could make of the result?

omg thank you, that solves the problem. but im still why int is a problem since int can hold 2 bytes of data which consist of 16 bits.

hakimarahman96:
omg thank you, that solves the problem. but im still why int is a problem since int can hold 2 bytes of data which consist of 16 bits.

because your code in making a NUMBER that 'looks' like the your bit array.

if you want to put the your bit array in the respective bit positions within an int variable, then you may want to try something like this:

void setup() {
  // put your setup code here, to run once:

  int bits[8] = {1, 0, 0, 0, 1, 0, 1, 0};
  int size = sizeof(bits) / sizeof(bits[0]);
  int number  = 0;
  int val  = 0;
  int n = size;

  Serial.begin(115200);

  //bit[0] into b0, bit[1] into b1, you get the idea... :)
  while (n > 0)
  {
    n--;
    val <<= 1;
    val = val | bits[n];
  }

  Serial.print("interger -- ");

  Serial.println(val, BIN);


}

void loop() {
  // put your main code here, to run repeatedly:

}

hope that helps...