java - 将 HEX 转换为 UINT32 Little Endian
问题描述
我正在 Android Studio 中编写应用程序,并且必须在 Java 中将十六进制值转换为 UINT32 Little Endian。我怎么做?
这是代码:
public void onNewIntent(Intent intent) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
info.setText(bytesToHex(tag.getId()));
String hex = bytesToHex(tag.getId()).replace(" ", "");
long value = Long.parseLong(hex, 16);
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.asLongBuffer().put(value);
buffer.order(ByteOrder.LITTLE_ENDIAN);
long kort_id = buffer.asLongBuffer().get();
SharedPreferences pref = getApplicationContext().getSharedPreferences("Storage", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putString("KortID", String.valueOf(kort_id));
editor.putBoolean("initializing", true);
editor.apply();
//Intent startMainActivity = new Intent(this, MainActivity.class);
//startActivity(startMainActivity);
//finish();
}
运行时出现 BufferOverflowException 错误。
解决方案
推荐阅读
- angular - Angular Fire 从同一集合中获取相关数据
- promql - Promql 按类别划分的成功百分比
- php - 将 MySQL 数据库中的值显示到日历中
- python - 如何用 BeautifulSoup [Python] 刮一张桌子
- amazon-web-services - 上传到 Amazon S3 时如何强制使用唯一文件名
- javascript - 在 Django 中单击按钮时未执行 JavaScript
- flutter - Flutter Scroll 在滑块中不起作用
- python-3.x - 如何使用python在一行中打印特定字符串的下一个单词?
- html - 有没有办法在 HTML 中制作一个按钮,当您每次单击它时,都会弹出一个新的预填充电子邮件?
- python - 在熊猫数据框图上拉伸 x 轴的一部分(绘制不均匀的 x 轴)