I currently work on some binary data. In order to check and debug the data previously generated by my application I use hexdump, facing the obstacle of hexdump not appearing to be able to extract a 64-bit integer field. Given the following minimal example:
#include <iostream>
#include <fstream>
#include <cstdint>
int main(int argc, char** argv){
std::ofstream os("tmp.bin", std::ios::out | std::ios::binary);
uint64_t x = 7;
os.write((char*)&x,sizeof(uint64_t));
os.close();
return 0;
}
I perform a simple hexdump on my system:
hexdump tmp.bin
> 0000000: 0007 0000 0000 0000
> 0000008:
Now trying to extract the unsigned int of 64 bit width yields:
hexdump -e '/8 "%u"' tmp.bin
> hexdump: bad byte count for conversion character u
According to the well written hexdump-manual by David Mair it should be possible to do it, but I have no success.
What am I missing ?
x=`hexdump -n 8 -e '2/4 "%08X " "\n"' $1 | awk 'BEGIN{printf "0x"}{print $2$1}'`; echo $(($x));
– Sacculate