endianness - c++ missing endianconvert method -
i have partial source code i'm trying reconstruct (don't ask rest is, not available) , i'm stuck @ missing method 'endianconvert'
i don't have experience c++ i'm hoping here can me out. heres function call
endianconvert (reinterpret_cast<dword *>(pdata+dwclassoffset), sizeof (pagetable) >> 2);
pdata byte array filled contents of file
byte * pdata = new byte[l];
dwclassoffset current location in file
dword dwclassoffset = 0;
and pagetable class containing several dword variables.
it looks need swap endianess of several dwords in byte array don't know how start implementing this, appreciated.
the >> 2
expression divides size of object in bytes 4, gives number of 4-byte words convert, start function something many times:
void endianconvert(dword* data, size_t count) { (size_t n = 0; n < count; ++n) /* convert data[n] */; }
now need able swap endianness of single dword, quite simple:
dword& d = data[n]; dword b1 = d & 0x000000ff; dword b2 = d & 0x0000ff00; dword b3 = d & 0x00ff0000; dword b4 = d & 0xff000000; d = (b1 << 24) | (b2 << 8) | (b3 >> 8) | (b4 >> 24);
extract each byte, shift position have in other endianness, , or bytes together.
Comments
Post a Comment