比如你要发送一个结构
struct test{
short a;
int b;
long c;
float d;
double f;
};
test st;
char *p = (char *)&st; //看看p中的字节顺序(就是发送的字节顺序)java端你相应写些函数进行转换就行了。举一个例子:
与c对应的ntohl函数
public static long ntohl(long in){
long out = 0;
out = (in&0xff)<<24;
out |= (in&0xff00)<<8;
out |= (in&0xff0000)>>8;
out |= (in&0xff000000)>>24;
return out;
}
struct test{
short a;
int b;
long c;
float d;
double f;
};
test st;
char *p = (char *)&st; //看看p中的字节顺序(就是发送的字节顺序)java端你相应写些函数进行转换就行了。举一个例子:
与c对应的ntohl函数
public static long ntohl(long in){
long out = 0;
out = (in&0xff)<<24;
out |= (in&0xff00)<<8;
out |= (in&0xff0000)>>8;
out |= (in&0xff000000)>>24;
return out;
}
http://blog.csdn.net/kingfish/archive/2005/03/29/333635.aspx
's' for short
'l' for long
int iNetToLocal(int value)
int iLocalTonet(int value)
short sNetToLocal(short value)
short sLocalToNet(short value)
谢谢了
比如FloatBuffer,LongBuffer,IntBuffer,ByteBuffer不过要注意格式,因为java中 int,float等都有一个字节顺序问题和采用的编码问题,Char就更是如此