Java 将图书的ISBN号转换为十六进制,以便写入RFID标签

Java 将图书的ISBN号转换为十六进制,以便写入RFID标签,java,rfid,hex,isbn,Java,Rfid,Hex,Isbn,我正在将ISBN值写入UHF RFID卡,因此我需要扫描书籍的条形码并接收ISBN,然后我需要将13位整数的ISBN转换为十六进制值以写入UHF RFID标签 到目前为止,我可以扫描条形码并接收ISBN号码,但我需要一些帮助,将ISBN转换为十六进制值,以便在Java中写入UHF RFID标签。您可以使用。创建一个toHex方法,如果输入字符串包含-则用空字符串替换它们,然后创建并返回数字。请注意,Long.valueOf可能引发NumberFormatException,例如 这不是“处理”N

我正在将ISBN值写入UHF RFID卡,因此我需要扫描书籍的条形码并接收ISBN,然后我需要将13位整数的ISBN转换为十六进制值以写入UHF RFID标签

到目前为止,我可以扫描条形码并接收ISBN号码,但我需要一些帮助,将ISBN转换为十六进制值,以便在Java中写入UHF RFID标签。

您可以使用。创建一个toHex方法,如果输入字符串包含-则用空字符串替换它们,然后创建并返回数字。请注意,Long.valueOf可能引发NumberFormatException,例如


这不是“处理”NumberFormatException的方法。由于它已经是RuntimeException,您应该让原始异常传播。@user1099280如果您提供的字符串不能转换为数字,例如II,则toHex方法将抛出NumberFormatException。你可以随意处理你确定这是必要的吗?这似乎是一个奇怪的要求。是的,这是非常需要的。
public static Long toHex(String isbn) {
    String temp = isbn;
    if (isbn.length() > 10) {
        temp = isbn.replaceAll("-", "");
    }

    return Long.valueOf(temp, 16);
}

public static void main(String[] args) {
        Long isbn1 = 9780071809L;
        Long isbn2 = 9780071809252L;

        System.out.println(toHex(isbn1.toString()));
        System.out.println(toHex(isbn2.toString()));
        System.out.println(toHex("978-0071809252"));
    }
   BigInteger toHex=new BigInteger(dec,10);// use this to convert your number to big integer so that any number can be stored where dec is your input number in base 10 in string
     String s=toHex.toString(16);//convert your number into hexa string which can be directly stored in rfid tag