Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中从c读取长字节_Java_C - Fatal编程技术网

在java中从c读取长字节

在java中从c读取长字节,java,c,Java,C,我必须从我的c程序中发送一个长消息,以便使用字节缓冲区在java代码中读取。我做了一些错误的事情,因为我无法发送1234并在java中读取它,因为它已损坏为564049465049088 在我的C代码中,我是这样做的 int64_t resultl = 1234; 然后复制 uint8_t * outBuffer <== pointer to the buffer; memcpy(outBuffer,&resultl,8); 这给了我错误的值564049465049088,因为

我必须从我的c程序中发送一个长消息,以便使用字节缓冲区在java代码中读取。我做了一些错误的事情,因为我无法发送1234并在java中读取它,因为它已损坏为564049465049088

在我的C代码中,我是这样做的

int64_t resultl = 1234;
然后复制

uint8_t * outBuffer <== pointer to the buffer;
memcpy(outBuffer,&resultl,8);
这给了我错误的值564049465049088,因为我从C发送了1234;
有人能告诉我我做错了什么吗?我怎样才能纠正同样的错误。

您必须更改ByteBuffer的结尾:

ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);

由于您可能使用的是小型endian计算机系统(x86和大多数ARM系统)。

您必须更改ByteBuffer的endian:

ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
因为您可能使用的是小型endian计算机系统(x86和大多数ARM系统)