I have a file with some binary data as follows.
aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55 aa 55
aa 55 aa 55 36 65 fb 5f 1e 92 d8 1b 55 f7 fb 5f
1e 92 d8 1b
I want to extract the values 55 36 65 fb 5f 1e
.
If I use the following code.
temp_1 = (data_ptr[offset]);
val = temp_1 << 40;
temp_1 = (data_ptr[offset + 1]);
val |= temp_1 << 32;
temp_1 = (data_ptr[offset + 2]);
val |= temp_1 << 24;
temp_1 = (data_ptr[ts_offset + 3]);
val |= temp_1 << 16;
temp_1 = (data_ptr[ts_offset + 4]);
val |= temp_1 << 8;
temp_1 = (data_ptr[ts_offset + 5]);
val |= temp << 0;
printf("read value %"PRIx64" \n",val);
The outupt of this printf is
3665fb5f1e92
Now I also try to calculate the same value using a single 64-bit ptr cast operation.
val = *(uint64_t*)(data_ptr + ts_offset);
printf("read value %"PRIx64" \n",val);
The output of the above code is
1bd8921e5ffb6536
If you check the least significant 48-bits here 921e5ffb6536
It is the inverted compared to the first result.I am using a normal intel processor.Why is this behaviour? Is this expected.