C++ / Arduino: How do I convert a string/char-array to byte?

arduino, arrays, byte, c++

Solution

I'm not sure about specific restrictions imposed by the Adruino platform, but this should work on any standard compiler.

char GetBitArrayAsByte(const char inputArray[8])
{
    char result = 0;
    for (int idx = 0; idx < 8; ++idx)
    {
        result |= (inputArray[7-idx] << idx);
    }
    return result;
}

A test of this code is now on Codepad, if that helps.

Problem

I want to convert ``` char lineOneC[8] = {0,1,1,0,0,0,0,1}; ``` into ``` byte lineOneB = B01100001; ``` How do I do this in C++ / Arduino?

Original source