EDIT: fixed wrong type num2.
Hello,
I have several arrays of characters of a known size that contains raw integer data read from a binary file.
The size of all these arrays is the size of integers.
I would like to ask if the following operation is safe and accurate under ALL normal conditions, assuming that the correspondence between the source data and the computer running this code is consistent.
char arr1[4] = { ... };
char arr2[2] = { ... };
uint32_t num1 = *static_cast<uint32_t*>(arr1);
uint16_t num2 = *static_cast<uint16_t*>(arr2);
Thank!
source
share