阅读"整数QUOT;面积从一个char *数组的字节。 [英] Reading "integer" size bytes from a char* array.

查看:188
本文介绍了阅读"整数QUOT;面积从一个char *数组的字节。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的sizeof(INT)的char * 字节数组

a)在什么情况下我们做我们需要担心如果字节顺序需要进行检查?

a) In what scenario's do we need to worry if endianness needs to be checked?

b)您会怎么看第4个字节要么以字节顺序考虑或没有。

b) How would you read the first 4 bytes either taking endianness into consideration or not.

编辑:我已阅读的sizeof(INT)字节,需要使用一个整数值进行比较

EDIT : The sizeof(int) bytes that I have read needs to be compared with an integer value.

什么是去了解这个问题的最好办法。

What is the best approach to go about this problem

推荐答案

你的意思是这样的:

char* a;
int i;
memcpy(&i, a, sizeof(i));

您只需要担心的字节顺序如果数据源是从不同的平台,就像一个设备。

You only have to worry about endianess if the source of the data is from a different platform, like a device.

这篇关于阅读"整数QUOT;面积从一个char *数组的字节。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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