Skip to content

Commit

Permalink
add simple hex reading to file_reader.h
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Oct 13, 2024
1 parent eb9782d commit 05995be
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions common/file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ class FileReader {
return -1;
}
}
int ReadHex1() {
int c = Read();
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
return -1;
}
int ReadHex2() {
int a = ReadHex1();
int b = ReadHex2();
if (a == -1 || b == -1) return -1;
return (a << 4) | b;
}
int Write(const uint8_t* dest, int bytes) {
RUN_ALL(write(dest, bytes))
return 0;
Expand Down

0 comments on commit 05995be

Please sign in to comment.