Java 整数到字节数组 Blackberry J2ME

标签 java java-me type-conversion blackberry-jde

我找到了this解决方案,但它似乎适用于 Java SE。我找不到 System.out.format() 函数的替代方法。另外,我已将 ByteBuffer.allocate() 函数更改为 ByteBuffer.allocateDirect() 这是正确的吗?

    byte[] bytes = ByteBuffer.allocate(4).putInt(1695609641).array();

    for (byte b : bytes) {
         System.out.format("0x%x ", b);
    }

谢谢。

最佳答案

如果你想要network byte order又名 big-endian 顺序,在 Java 的序列化和远程处理库中使用:

static byte[] intToBytesBigEndian(int i) {
  return new byte[] {
    (byte) ((i >>> 24) & 0xff),
    (byte) ((i >>> 16) & 0xff),
    (byte) ((i >>> 8) & 0xff),
    (byte) (i & 0xff),
  };
}

关于Java 整数到字节数组 Blackberry J2ME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587605/

相关文章:

python - '020-06-08 17 :11:02+00:00' I want to extract the date from this time format in Python using datetime

java - href 语句中的正斜杠 '/' 保持恢复为反斜杠 '\' .jnlp 文件

java - Spring MVC 下拉列表

java - 如何舍入数学方程式的答案

java - 在 Symbian 上如何将 TextView 的内容保存到文件中?

java - J2ME Midlet和PC之间如何通信?

java - Elasticsearch,文档中数组大小的总和

java - Java Mobile 中的蓝牙 : Handling connections that go out of range

c++ - 关于 C++ 中常量的隐式转换

java - Java 中的 Long 到 int 的转换给出了不正确的结果