add mising b2s function

This commit is contained in:
King Kévin 2016-04-09 23:19:19 +02:00
parent 246d35ac2f
commit 09abc891a2
1 changed files with 22 additions and 0 deletions

22
main.c
View File

@ -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<rjust && bit>=0) {
string[bit--] = '0';
}
return &string[bit+1];
}
/** @brief switch off all clock LEDs
* @note LEDs need to be set separately
*/