int read_bsd_byte(int *count = NULL, int *sum = NULL) { char c; if (file.read(&c, 1) != 1) throw TruncatedRead(); if (sum) *sum += (0xff & c); if (count) *count += 1; return (0xff & c) - (int(c/16)*6); }
int read_bytes(int len, int *count = NULL, int *sum = NULL) { char c; int res = 0; for (int i = 0; i < len; ++i) { if (file.read(&c, 1) != 1) throw TruncatedRead(); if (sum) *sum += (0xff & c); if (count) *count += 1; res += pow(256,i) * (0xff & c); } return res; }
QString read_text(int len, int *count = NULL, int *sum = NULL) { char c; QString res = ""; for (int i = 0; i < len; ++i) { if (file.read(&c, 1) != 1) throw TruncatedRead(); if (sum) *sum += (0xff & c); if (count) *count += 1; res += c; } return res; }
int read_bytes(int len, int *count = NULL, int *sum = NULL, bool issigned = false) { char c; int res = 0; for (int i = 0; i < len; ++i) { if (file.read(&c, 1) != 1) throw TruncatedRead(); if (sum) *sum += (0xff & c); if (count) *count += 1; res += pow(256,i) * (0xff & (unsigned) c) ; if (issigned && i == len-1) res = res - (0x80 & (unsigned) c) * 2 ; } return res; }