From 09abc891a2bffcb838e3c351082ebbdfc5855d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 9 Apr 2016 23:19:19 +0200 Subject: [PATCH] add mising b2s function --- main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 */