简体   繁体   English

在 Java 中加载 C 签名长

[英]Load C signed long in Java

I have a 4-byte signed long variable in C/C++ which is saved in a file using memcpy.我在 C/C++ 中有一个 4 字节有signed long变量,它使用 memcpy 保存在文件中。

File content: "31E04CFB".文件内容:“31E04CFB”。

I need to load this value in Java, but Java's int (4 bytes) and C++'s long have different memory structures.我需要在 Java 中加载这个值,但是 Java 的int (4 字节)和 C++ 的long有不同的 memory 结构。 Is there any library which will help me with this, or I have to code it myself?是否有任何图书馆可以帮助我解决这个问题,或者我必须自己编写代码?

Are you the one writing the file?你是写文件的人吗? Do you understand about big-endian versus little-endian?你了解大端与小端吗?

If you want a portable file, writing raw bytes isn't how you do it.如果你想要一个可移植的文件,写原始字节不是你的做法。 Do you have the choice of a different file format?您可以选择不同的文件格式吗?

If so, consider it.如果是这样,考虑一下。 Store it as a string instead of raw bytes.将其存储为字符串而不是原始字节。

If not, then you need to understand the big-endian /little-endian status on the hardware you're using, and it will NOT be portable.如果没有,那么您需要了解您正在使用的硬件上的大端/小端状态,它不会是可移植的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM