我正在为操作系统 Rodos 实现从 C++ 到 Java 的通信接口。我的 C++ 有点“生锈”,而且我以前从未见过这个操作:header+0
对于一个数组!
rodos/api/gateway/networkmessage.h:
class NetworkMessage {
static const int HEADER_SIZE = 26;
uint8_t header [HEADER_SIZE];
public:
inline void put_checkSum(uint16_t x) {int16_tToBigEndian(header+0, x); }
inline void put_senderNode(int32_t x) {int32_tToBigEndian(header+2, x); }
rodos/support_libs/stream-bytesex.cpp:
void int16_tToBigEndian(void* buff, uint16_t value) {
uint8_t* byteStream = (uint8_t*)buff;
if (byteStream == 0) return;
byteStream[0] = (uint8_t) ((value >> 8) & 0xFF);
byteStream[1] = (uint8_t) ((value >> 0) & 0xFF);
}
如何在 Java 中实现整数数组和整数的加法?