开发者

Convert double to int on Arm RVCT compiler in C language

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜