mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
Fix a bug in hex_to_ascii().
This commit is contained in:
parent
7aff64740e
commit
b53590fe3a
@ -25,17 +25,13 @@ void hex_to_ascii(int n, char str[]) {
|
||||
|
||||
s32 tmp;
|
||||
int i;
|
||||
for (i = 28; i > 0; i -= 4) {
|
||||
for (i = 28; i >= 0; i -= 4) {
|
||||
tmp = (n >> i) & 0xF;
|
||||
if (tmp == 0 && zeros == 0) continue;
|
||||
zeros = 1;
|
||||
if (tmp > 0xA) append(str, tmp - 0xA + 'a');
|
||||
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
|
||||
else append(str, tmp + '0');
|
||||
}
|
||||
|
||||
tmp = n & 0xF;
|
||||
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
|
||||
else append(str, tmp + '0');
|
||||
}
|
||||
|
||||
/* K&R */
|
||||
|
@ -25,17 +25,13 @@ void hex_to_ascii(int n, char str[]) {
|
||||
|
||||
int32_t tmp;
|
||||
int i;
|
||||
for (i = 28; i > 0; i -= 4) {
|
||||
for (i = 28; i >= 0; i -= 4) {
|
||||
tmp = (n >> i) & 0xF;
|
||||
if (tmp == 0 && zeros == 0) continue;
|
||||
zeros = 1;
|
||||
if (tmp > 0xA) append(str, tmp - 0xA + 'a');
|
||||
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
|
||||
else append(str, tmp + '0');
|
||||
}
|
||||
|
||||
tmp = n & 0xF;
|
||||
if (tmp >= 0xA) append(str, tmp - 0xA + 'a');
|
||||
else append(str, tmp + '0');
|
||||
}
|
||||
|
||||
/* K&R */
|
||||
|
Loading…
Reference in New Issue
Block a user