diff --git a/main.c b/main.c index 2ebbe02..cc7b328 100644 --- a/main.c +++ b/main.c @@ -129,6 +129,28 @@ int _write(int file, char *ptr, int len) return -1; } +char* b2s(uint32_t binary, uint8_t rjust) +{ + static char string[32+1] = {0}; // the string representation to return + int16_t bit = LENGTH(string)-1; // the index of the bit to print + string[bit--] = 0; // terminate string + + while (binary) { + if (binary & 1) { + string[bit--] = '1'; + } else { + string[bit--] = '0'; + } + binary >>= 1; + } + + while (32-bit-1=0) { + string[bit--] = '0'; + } + + return &string[bit+1]; +} + /** @brief switch off all clock LEDs * @note LEDs need to be set separately */