Binary to Decimal conversion in arduino

Hello,
I am using Arduino mega. I have an array containing binary data. I want to convert this array of binary data into decimal numbers. I am using the following code. The problem is that the following code returns a decimal number 8 instead of 9. If I run the same code in the online C compiler, I get the correct decimal value.
Why is this so? Why Arduino is not able to calculate the results correctly?

Here is my Arduino code:-

/*****************************************/
uint8_t a[] = {1,0,0,1};
int b= 0;
void setup()
{
Serial.begin(9600);
int k = 0;
for(int i = 3; i>=0; i–)
{
b += a _
pow(2, k);_

  • k++;*
  • }*
  • Serial.println(b);*
    }
    void loop() {}
    /*******************************************/
    Here is my C code which I tried in online compiler:
    /******************************************/
    #include <stdio.h>
    #include<math.h>
    int main()
    {
  • int a = {1,0,0,1};*
  • int b = 0;*
  • int k = 0;*
  • for(int i = 3; i>=0; i–)*
  • {*
    b += a * pow(2, k);
    * k++;*
    * }*
    * printf("%d",b);*

* return 0;*
}
/**************************************/



Please post your actual code rather than a picture of it

Don’t ever use pow to calculate powers of two.
Use shift operators

And code tags, we love code tags.