如何从s64值中删除前3个字节和最后一个字节? [英] How to remove the first 3 bytes and last one byte from s64 value?

查看:274
本文介绍了如何从s64值中删除前3个字节和最后一个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

s64 end_time;
struct timespec ts;
getrawmonotonic(&ts);
end_time = timespec_to_ns(&ts);

如何删除 end_time的前三个字节和最后一个字节从它?
我想把它存储在uint32。
有人可以告诉我怎么做?

How to remove the first three bytes from end_time and last one byte from it?? I want to store it in a uint32. could someone tell me how to do that??

uint32 latency;
fscanf(fp, "%lu\n", latency);  //fp  is reading the end_time and storing in latency.
latency = (uint32) (latency >> 8) & 0xFFFFFFFF;


推荐答案

如何:

u32 end_time32 = (u32) (end_time >> 24) & 0xFFFFFFFF;

根据您对的定义 code> last byte它也可以是:

Depending on your definition of first and last byte it could also be:

u32 end_time32 = (u32) (end_time >> 8) & 0xFFFFFFFF;

示例:

s64 end_time = 0x1234567890ABCDEF;
u32 end_time32 = (u32) (end_time >> 24) & 0xFFFFFFFF;

// end_time32 is now: 0x34567890

s64 end_time = 0x1234567890ABCDEF;
u32 end_time32 = (u32) (end_time >> 8) & 0xFFFFFFFF;

// end_time32 is now: 0x7890ABCD

strong>

Edit

更新问题后:

s64 latency;
fscanf(fp, "%lld", latency);  //fp  is reading the end_time and storing in latency.
u32 latency32 = (uint32) (latency >> 8) & 0xFFFFFFFF;

这篇关于如何从s64值中删除前3个字节和最后一个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆