Using the following code to write to a file
int main(int argc, char * argv[])
{
uint32_t pattern1, pattern2;
int i, times;
sscanf("ae75db0f", "%x", &pattern1);
sscanf("518a24f0", "%x", &pattern2);
FILE * outFile = fopen(argv[1],"wb");
printf ("Pattern 1: %0x \nPattern 2: %0x \n", pattern1, pattern2);
times = 524288; // Write out 4 mB of data
for (i = 0; i < times; i++) {
fwrite(&pattern1, 4, 1, outFile);
fwrite(&pattern2, 4, 1, outFile);
}
fclose (outFile);
}
On the command line I do xxd file | less
00018c0: f024 8a51 0fdb 75ae f024 8a51 0fdb 75ae .$.Q..u..$.Q..u.
00018d0: f024 8a51 0fdb 75ae f024 8a51 0fdb 75ae .$.Q..u..$.Q..u.
00018e0: f024 8a51 0fdb 75ae f024 8a51 0fdb 75ae .$.Q..u..$.Q..u.
00018f0: f024 8a51 0fdb 75ae f024 8a51 0fdb 75ae .$.Q..u..$.Q..u.
It’s not showing the “correct” values that were supposed to be written to the file itself.
Welcome to the world of the endianness:
http://en.wikipedia.org/wiki/Endianness
x86/x64 architectures (like most architectures nowadays) are little endian: it means multi-bytes values are stored in memory with the Least Significant Bytes first (low memory address).