gpt4 book ai didi

java - 如何转换例如 : (int)5 to (byte)0x05 in Java?

转载 作者:行者123 更新时间:2023-11-29 08:07:24 25 4
gpt4 key购买 nike

我试过:

int amount = 5;
String amountStr = "0x0" + amount;
byte newByte = Byte.parsByte(amountStr);

但是我得到 java.lang.NumberFormatException: For input string: "0x05"

最佳答案

如果你想解析一个字符串,使用Byte#decode :

byte newByte = Byte.decode(amountStr);

否则你可以直接转换它(如评论中所写)。

关于java - 如何转换例如 : (int)5 to (byte)0x05 in Java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10233236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com