When we cast an uint64_t to an uint32_t, I see by reading cppreference that truncation happens.
But, what bits are truncated? The higher or lower bits? How is this decided, and why?
When we cast an uint64_t to an uint32_t, I see by reading cppreference that truncation happens.
But, what bits are truncated? The higher or lower bits? How is this decided, and why?
The resulting value is the unique value equal to the original one modulo 232 that can be represented by
uint32_t. In other words, only the 32 least significant bits in the base-2 representation of the value remain and all others (in your case the 32 most significant bits) are truncated.Whether these bits are high or low (or neither) in the object representation of
uint64_tis implementation-defined and depends especially on the endianess of the architecture.