Serialize key states much more efficiently by using bits instead of bytes.

This commit is contained in:
László Monda
2017-05-31 01:26:16 +02:00
parent 8b69dd7d90
commit 0edd56fa82
4 changed files with 40 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
#include <string.h>
#include "bool_array_converter.h"
void BoolBytesToBits(uint8_t *srcBytes, uint8_t *dstBits, uint8_t byteCount)
{
memset(dstBits, 0, byteCount/8 + 1);
for (uint8_t i=0; i<byteCount; i++) {
dstBits[i/8] |= (srcBytes[i] ? 1 : 0) << (i % 8);
}
}
void BoolBitsToBytes(uint8_t *srcBits, uint8_t *dstBytes, uint8_t byteCount)
{
for (uint8_t i=0; i<byteCount; i++) {
dstBytes[i] = (srcBits[i/8] & (1 << (i % 8))) ? 1 : 0;
}
}