fix index

This commit is contained in:
King Kévin 2016-08-20 23:24:49 +02:00
parent 545b0be96e
commit 3c4a1ae976
1 changed files with 4 additions and 4 deletions

View File

@ -35,8 +35,8 @@ volatile bool button_flag = false;
char* b2s(uint64_t binary, uint8_t rjust) char* b2s(uint64_t binary, uint8_t rjust)
{ {
static char string[64+1] = {0}; // the string representation to return static char string[64+1] = {0}; // the string representation to return
int8_t bit = LENGTH(string)-1; // the index of the bit to print uint8_t bit = LENGTH(string)-1; // the index of the bit to print
string[bit--] = 0; // terminate string string[bit--] = '\0'; // terminate string
while (binary) { while (binary) {
if (binary & 1) { if (binary & 1) {
@ -47,11 +47,11 @@ char* b2s(uint64_t binary, uint8_t rjust)
binary >>= 1; binary >>= 1;
} }
while (64-bit-1<rjust && bit>=0) { while (64-bit-1<rjust && bit>0) {
string[bit--] = '0'; string[bit--] = '0';
} }
return &string[bit+1]; return string;
} }
/** switch on board LED */ /** switch on board LED */