How to read from a file with hex address

I need to read an entry from a packed file by it's hex address but i'm not sure how to approach this. Here's how an entry from reference file looks like:
 
filename[8 digit hex address of starting point in packed file][number of bytes in filename(as 8 digit hex)]


(Error checking omitted.)
1
2
3
4
std::ifstream file(filename, std::ios::binary);
file.seekg(offset);
file.read(buffer, buffer_size);
auto actual_bytes_read = file.gcount();
Thanks for the reply. But i'm having hard time to cast hex address and file size to offset.

00 80 08 00

This is one of the file sizes in hex. But it's actually being calculated in reverse order so:

00 08 80 00

is the actual file size. How should i cast it to offset ?
You have to flip the bytes, it can't be done with a cast.
1
2
std::uint32_t raw_value = /*...*/;
std::uint32_t actual_value = (raw_value << 24) | ((raw_value & 0xFF00) << 8) | ((raw_value & 0xFF0000) >> 8) | ((raw_value >> 24) & 0xFF);
Last edited on
Thanks for help.
Topic archived. No new replies allowed.