【发布时间】:2020-07-29 15:33:15
【问题描述】:
我是 arduino 编程 (c/c+) 的新手。并且想将带有布尔值的数组转换为类似字节的数组。布尔值在这里表示一个按钮。
bool array[] = {0,1,1,0}; // needs to convert to 0b0110
// bool array[] = {1,0,0,0}; // needs to convert to 0b1000
// bool array[] = {true,true,false,true}; // needs to convert to 0b1101
void setup(){
byte b = convert(array); // 0b0110
}
byte convert(bool array[]){
byte b = 0b + 0 + 1 + 1 + 0; // <- wrong stuff here :(
return b;
}
【问题讨论】: