如何从long中提取字节? [英] How to extract bytes from long?

查看:150
本文介绍了如何从long中提取字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从最后一个字节开始从long中提取字节?

例如,我有一个很长的数字:

0x12345678

我需要将它表示为以下字节列表:

0x78,0x56,0x34,0x12


提前致谢,

Rita

How to extract bytes from long, starting from the last byte?
For example, I have a long number:
0x12345678
I need to represent it as the following bytes list:
0x78, 0x56, 0x34, 0x12

Thanks in advance,
Rita

推荐答案

RB写道:
如何从最后一个字节开始从long中提取字节?
例如,我有一个很长的数字:
0x12345678
我需要将它表示为以下字节列表:
0x78,0x56,0x34,0x12

谢谢提前,
Rita
How to extract bytes from long, starting from the last byte?
For example, I have a long number:
0x12345678
I need to represent it as the following bytes list:
0x78, 0x56, 0x34, 0x12

Thanks in advance,
Rita




查看按位运算符。 &,|,^,<<,>>。然后查看位掩码

以及如何使用它们,一切都应该相当简单。


-

Thomas。

未来所有语言的存在是什么



Look at bitwise operators. &, |, ^, <<, >>. Then look up bitmasks
and how to use them and everything should be rather straightforward.

--
Thomas.
"What is the future c existence which does not do in all languages"


2003年10月15日星期三01:59 :04:0700,RB写道:
On Wed, 15 Oct 2003 01:59:04 -0700, RB wrote:
如何从最后一个字节开始从long中提取字节?
How to extract bytes from long, starting from the last byte?




# include< stdio.h>


int main(){


无符号长值= 0x12345678;

int i;


printf("%#lx \ n",value);


for(i = sizeof value; i > 0; --i){

printf("%#x \ n",value& 0xff);

value>> = 8 ;

}

返回0;

}


-

NPV


大字印刷品,小字体带走

Tom Waits - 向上走吧




RB写道:


RB wrote:
如何从最后一个字节开始从long中提取字节?
例如,我有一个很长的数字:
0x12345678
我需要将它表示为以下字节列表:
0x78,0x56,0x34,0x12

谢谢提前,
丽塔
How to extract bytes from long, starting from the last byte?
For example, I have a long number:
0x12345678
I need to represent it as the following bytes list:
0x78, 0x56, 0x34, 0x12

Thanks in advance,
Rita




听起来有点作业 - 但是作为一个提示试试这个:


#include< stdio.h>


int main(无效)

{

长val = 0x12345678;


printf(" 0x%x \ n",val>> 16& 0xff);


返回0;

}


问候,


Ed。



Sounds a bit homework-y, but as a hint try this:

#include <stdio.h>

int main(void)
{
long val=0x12345678;

printf("0x%x\n",val >> 16 & 0xff );

return 0;
}

Regards,

Ed.


这篇关于如何从long中提取字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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