开发者

Convert double to int on Arm RVCT compiler in C language

开发者 https://www.devze.com 2022-12-31 15:01 出处:网络
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.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消