40 lines
878 B
C++
40 lines
878 B
C++
#include "Utils.h"
|
|
|
|
std::string Utils::readString(std::istream& r, int len) {
|
|
std::string result;
|
|
for (int i = 0; i < len; i++) {
|
|
char c;
|
|
if (r.get(c)) {
|
|
result += c;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int Utils::readByte(std::istream& r) {
|
|
char hex[3];
|
|
hex[0] = r.get();
|
|
hex[1] = r.get();
|
|
hex[2] = '\0';
|
|
|
|
int value = 0;
|
|
for (int i = 0; i < 2; i++) {
|
|
value <<= 4;
|
|
char c = hex[i];
|
|
if (c >= '0' && c <= '9') {
|
|
value += c - '0';
|
|
} else if (c >= 'A' && c <= 'F') {
|
|
value += c - 'A' + 10;
|
|
} else if (c >= 'a' && c <= 'f') {
|
|
value += c - 'a' + 10;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
int Utils::readWord(std::istream& r) {
|
|
int b1 = readByte(r);
|
|
int b2 = readByte(r);
|
|
int b3 = readByte(r);
|
|
return (b1 << 16) | (b2 << 8) | b3;
|
|
}
|