st-anything/lib/RCSwitch/examples/ReceiveDemo_Advanced/helperfunctions.ino

21 lines
428 B
Arduino
Raw Normal View History

2023-03-11 14:11:03 +00:00
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
static char bin[64];
unsigned int i=0;
while (Dec > 0) {
bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';
Dec = Dec >> 1;
}
for (unsigned int j = 0; j< bitLength; j++) {
if (j >= bitLength - i) {
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
}else {
bin[j] = '0';
}
}
bin[bitLength] = '\0';
return bin;
}