math: correct hexc_to_int
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
0d03ff47d4
commit
260ed8a013
1 changed files with 5 additions and 5 deletions
10
lib/math.c
10
lib/math.c
|
|
@ -40,9 +40,9 @@ static int hexc_to_int(char c)
|
|||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
return c - 'F';
|
||||
return c - 'A' + 10;
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
return c - 'a';
|
||||
return c - 'a' + 10;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -52,13 +52,13 @@ u64 hex_to_int(char *ascii_hex, size_t n)
|
|||
u64 ret = 0;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
char c = ascii_hex[i];
|
||||
int i = hexc_to_int(c);
|
||||
int val = hexc_to_int(c);
|
||||
|
||||
if (i < 0)
|
||||
if (val < 0)
|
||||
break;
|
||||
|
||||
ret <<= 4;
|
||||
ret |= i;
|
||||
ret |= val;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in a new issue