I need to get last four bytes out of a double variable .The platform is Arm and compiler is R开发者_运维百科VCT.Programming language used is C.What is the safest way.
Thanks
int lastFour = *(((char*) &origDouble) + sizeof(double) - 4)
double dval = 3.14159;
// as an int
uint32_t ival = *(uint32_t*)&dval;
// as bytes
uint8_t *all_bytes = (uint8_t*)&dval;
uint8_t *last_four_bytes = all_bytes + 4;
精彩评论