Simplify bool array converter functions.
This commit is contained in:
@@ -5,13 +5,13 @@ void BoolBytesToBits(uint8_t *srcBytes, uint8_t *dstBits, uint8_t byteCount)
|
|||||||
{
|
{
|
||||||
memset(dstBits, 0, byteCount/8 + 1);
|
memset(dstBits, 0, byteCount/8 + 1);
|
||||||
for (uint8_t i=0; i<byteCount; i++) {
|
for (uint8_t i=0; i<byteCount; i++) {
|
||||||
dstBits[i/8] |= (srcBytes[i] ? 1 : 0) << (i % 8);
|
dstBits[i/8] |= !!srcBytes[i] << (i % 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolBitsToBytes(uint8_t *srcBits, uint8_t *dstBytes, uint8_t byteCount)
|
void BoolBitsToBytes(uint8_t *srcBits, uint8_t *dstBytes, uint8_t byteCount)
|
||||||
{
|
{
|
||||||
for (uint8_t i=0; i<byteCount; i++) {
|
for (uint8_t i=0; i<byteCount; i++) {
|
||||||
dstBytes[i] = (srcBits[i/8] & (1 << (i % 8))) ? 1 : 0;
|
dstBytes[i] = !!(srcBits[i/8] & (1 << (i % 8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user