add mising b2s function
This commit is contained in:
parent
246d35ac2f
commit
09abc891a2
22
main.c
22
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<rjust && bit>=0) {
|
||||
string[bit--] = '0';
|
||||
}
|
||||
|
||||
return &string[bit+1];
|
||||
}
|
||||
|
||||
/** @brief switch off all clock LEDs
|
||||
* @note LEDs need to be set separately
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue