我正在将ISBN值写入UHF RFID卡的过程中,因此我需要扫描图书的条形码并接收ISBN,然后我需要将ISBN (13位整数)转换为十六进制值以写入UHF RFID标签。
到目前为止,我可以扫描条形码和接收ISBN号码,但我需要一些帮助转换ISBN到十六进制值写入超高频RFID标签在Java中。
发布于 2018-09-23 23:07:13
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发布于 2014-12-22 16:03:05
您可以使用Long.valueOf(isbnString, 16)。创建一个toHex方法,如果输入字符串包含"-",则用空字符串替换它们,然后创建并返回数字。请注意,Long.valueOf可以抛出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"));
}https://stackoverflow.com/questions/27598629
复制相似问题