-
[프로그래밍] Byte order2011.10.12 PM 03:30
Network byteorder use big endian so application must handle the byte order in little endian system
here is sample
int getUint32(unsigned char * data, int index)
{
return ((data[index] & 0xff) << 24) | ((data[index + 1] & 0xff) << 16) | ((data[index + 2] & 0xff) << 8) | (data[index + 3] & 0xff);
}
void setUint32(unsigned char * data, int index, int i)
{
data[index] = (byte)(0xff & (i >> 24));
data[index + 1] = (byte)(0xff & (i >> 16));
data[index + 2] = (byte)(0xff & (i >> 8));
data[index + 3] = (byte)(0xff & i);
}
int getUint16(unsigned char * data, int index)
{
return (int)(((data[index] & 0xff) << 8) | (data[index + 1] & 0xff));
}
void setUint16(unsigned char * data, int index, int i)
{
data[index] = (byte)(i >> 8);
data[index + 1] = (byte)i;
}
댓글 : 0 개
user error : Error. B.