static unsigned int read24(unsigned char *ptr)
{
unsigned int b0;
unsigned int b1;
unsigned int b2;
unsigned int b3;
b0 = *ptr++;
b1 = *ptr++;
b2 = *ptr++;
b3 = *ptr;
return (((b0 >> 24) & 0x000000ff) |
((b1 >> 8) & 0x0000ff00) |
((b2 << 8) & 0x00ff0000) |
(b3 << 24) & 0x00000000 // this byte is not important so make it zero
);
}
在这里,我写了一个功能,我试图用字符指针读取32位(4字节),并返回的32位(4字节)。我有个疑问如果这将正常工作。另外,我是通过定义4个不同的整数变量来使用/浪费太多的内存吗?有没有更好的方法来编写这个函数。感谢您的时间。使用字符指针读取一个int值,并将其返回
我认为它会返回'1'或者'0'。 – Himanshu 2015-04-03 05:34:26
'read24'与“* ...试图读取32位*”:请解释。 – alk 2015-04-03 09:21:44
我读了4个字节......但我让最后一个字节为零,因为它对我来说不是那么重要.....最后我返回返回4byte值......这实际上就像0x 00xxxxxx ...因此read24 – 2015-04-03 10:02:45