【发布时间】:2019-03-02 11:52:09
【问题描述】:
您好,我想将字节数组,即 0x3eb 转换为短格式,因此我将 0x3eb 视为字符串并尝试转换为短格式,但它会抛出 Numberformat 异常......请帮助我
import java.io.UnsupportedEncodingException;
public class mmmain
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String ss="0x03eb";
Short value = Short.parseShort(ss);
System.out.println("value--->"+value);
}
}
Exception what im getting is
Exception in thread "main" java.lang.NumberFormatException:
For input string: "0x3eb" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:491)
at java.lang.Short.parseShort(Short.java:117)
at java.lang.Short.parseShort(Short.java:143)
at mmmain.main(mmmain.java:14)
即使我尝试将 0x3eb 转换为字节
byte[] bytes = ss.getBytes();
但我没有找到任何将字节解析为短的实现。
提前致谢
【问题讨论】:
标签: java arrays casting short typecasting-operator