首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将图书的ISBN号转换为HexaDecimal以便写入RFID标签

将图书的ISBN号转换为HexaDecimal以便写入RFID标签
EN

Stack Overflow用户
提问于 2014-12-22 15:52:50
回答 2查看 182关注 0票数 0

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

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

EN

回答 2

Stack Overflow用户

发布于 2018-09-23 23:07:13

代码语言:javascript
复制
   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
票数 0
EN

Stack Overflow用户

发布于 2014-12-22 16:03:05

您可以使用Long.valueOf(isbnString, 16)。创建一个toHex方法,如果输入字符串包含"-",则用空字符串替换它们,然后创建并返回数字。请注意,Long.valueOf可以抛出NumberFormatException

代码语言:javascript
复制
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"));
    }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27598629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档