如何访问LONGLONG值的各个字节 [英] How to access the individual bytes of LONGLONG value

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

问题描述



有人能告诉我如何访问包含Windows LONGLONG值的
的单个字节吗?

Hi,
Could anybody tell me how to access the individual bytes that consists
of a Windows LONGLONG value?

推荐答案

2006-03-21,shaji< sh *********** @ gmail.com>写道:
On 2006-03-21, shaji <sh***********@gmail.com> wrote:
有人能告诉我如何访问由Windows LONGLONG值组成的单个字节吗?
Hi, Could anybody tell me how to access the individual bytes that
consists of a Windows LONGLONG value?




以同样的方式访问任何类型的单个字节。



Same way you access the individual bytes for any type.


shaji写道:

有人可以告诉我如何访问包含Windows LONGLONG值的单个字节?
Hi,
Could anybody tell me how to access the individual bytes that consists
of a Windows LONGLONG value?




可用的解决方案是使用位移:


unsigned char bytes [8]; / * 0最不重要,7最多

重要* /

unsigned long long number;


/ *获得最少有效字节* /

char [0] =数字& 0xff;

/ *获取下一个字节* /

char [1] =(number>> 8)& 0xff;


/ *得到最重要的字节* /

char [7] =(number>> 56)& 0xff;


当然,你可以使用for循环,但我将把它作为一个

练习留给OP。



The protable solution is to use bit shifts:

unsigned char bytes[8]; /* 0 is least significant, 7 is most
significant */
unsigned long long number;

/* get least significant byte */
char[0] = number & 0xff;
/* get next byte */
char[1] = (number >> 8) & 0xff;

/* get most significant byte */
char[7] = (number >> 56) & 0xff;

Of course, you can use a for loop for this but I''m leaving that as an
exercise to the OP.


sl ******* @ yahoo.com schrieb:
shaji写道:
shaji wrote:

有人可以告诉我如何访问包含的单个字节
Windows LONGLONG值?
可用的解决方案是使用位移:

unsigned char bytes [8]; / * 0是最不重要的,7是最重要的* /
无符号长多数;
Hi,
Could anybody tell me how to access the individual bytes that consists
of a Windows LONGLONG value?
The protable solution is to use bit shifts:

unsigned char bytes[8]; /* 0 is least significant, 7 is most
significant */
unsigned long long number;




便携式解决方案可能会读取

unsigned long long number;

unsigned char bytes [sizeof number];
/ *得到最低有效字节* /
char [0] = number& ; 0xff;
/ *获取下一个字节* /
char [1] =(number>> 8)& 0xff;

/ *得到最重要的字节* /
char [7] =(number>> 56)& 0xff;

当然,您可以使用for循环,但我将其作为OP的练习。



The portable solution probably would read
unsigned long long number;
unsigned char bytes[sizeof number];
/* get least significant byte */
char[0] = number & 0xff;
/* get next byte */
char[1] = (number >> 8) & 0xff;

/* get most significant byte */
char[7] = (number >> 56) & 0xff;

Of course, you can use a for loop for this but I''m leaving that as an
exercise to the OP.



循环对于便携式解决方案是必需的。

char [i] =(number>>(i * CHAR_BIT))& (unsigned char)~0UL


干杯

Michael

-

电子邮件:我的是/ at / gmx / dot / de地址。



The loop is necessary for the portable solution.
char[i] = (number >> (i*CHAR_BIT)) & (unsigned char)~0UL

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


这篇关于如何访问LONGLONG值的各个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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