Fix bug reading hex values
This commit is contained in:
parent
42396701e0
commit
e320dc59f4
6
main.c
6
main.c
|
@ -114,11 +114,11 @@ bool read_hex_byte(char *buf, char *val) {
|
||||||
bool read_hex_i32(char *buf, int32_t *val) {
|
bool read_hex_i32(char *buf, int32_t *val) {
|
||||||
char byte;
|
char byte;
|
||||||
*val = 0;
|
*val = 0;
|
||||||
for (int i = 0; i < 8; i += 2) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
if (!read_hex_byte(buf + i, &byte)) {
|
if (!read_hex_byte(buf + (i * 2), &byte)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*val |= ((int32_t) (uint8_t) byte) << i;
|
*val |= ((int32_t) (uint8_t) byte) << (i * 8);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue