This commit is contained in:
Garen Chan 2023-09-21 11:42:05 -07:00 committed by GitHub
commit ff7ae0176e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View File

@ -25,17 +25,13 @@ void hex_to_ascii(int n, char str[]) {
s32 tmp; s32 tmp;
int i; int i;
for (i = 28; i > 0; i -= 4) { for (i = 28; i >= 0; i -= 4) {
tmp = (n >> i) & 0xF; tmp = (n >> i) & 0xF;
if (tmp == 0 && zeros == 0) continue; if (tmp == 0 && zeros == 0) continue;
zeros = 1; zeros = 1;
if (tmp > 0xA) append(str, tmp - 0xA + 'a'); if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
else append(str, tmp + '0'); else append(str, tmp + '0');
} }
tmp = n & 0xF;
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
else append(str, tmp + '0');
} }
/* K&R */ /* K&R */

View File

@ -25,17 +25,13 @@ void hex_to_ascii(int n, char str[]) {
int32_t tmp; int32_t tmp;
int i; int i;
for (i = 28; i > 0; i -= 4) { for (i = 28; i >= 0; i -= 4) {
tmp = (n >> i) & 0xF; tmp = (n >> i) & 0xF;
if (tmp == 0 && zeros == 0) continue; if (tmp == 0 && zeros == 0) continue;
zeros = 1; zeros = 1;
if (tmp > 0xA) append(str, tmp - 0xA + 'a'); if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
else append(str, tmp + '0'); else append(str, tmp + '0');
} }
tmp = n & 0xF;
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
else append(str, tmp + '0');
} }
/* K&R */ /* K&R */