C++/阿杜伊诺 : How do I convert a string/char-array to byte?

标签 c++ byte arduino arrays

我要转换

char lineOneC[8] = {0,1,1,0,0,0,0,1}; 

进入

byte lineOneB = B01100001;

我如何在 C++/Arduino 中执行此操作?

最佳答案

我不确定 Adruino 平台施加的具体限制, 但这应该适用于任何标准编译器。

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 , 如果说 有帮助。

关于C++/阿杜伊诺 : How do I convert a string/char-array to byte?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4369948/

相关文章:

c++ - ComboBoxEx32 (CComboBoxEx) 键盘行为

C++ 将字符串转换为字符数组

c++ - 为什么 std::cbegin() 不在容器上调用 .cbegin() ?

python - 如何将字节保存为图像?

ios - Objective-C警告,使用未声明的标识符“new”

c# - C# 中 MSpaint 图像的图像步幅为 +1 字节,为什么?

compiler-errors - 可以正常工作的Arduino UNO代码在ESP8266上编译错误-无匹配功能

c++ - Rcpp:将两个 NumericVectors 相乘,同时对其中一个进行子集化

Arduino 代码不工作

c++ - xilinx芯片有多常用?