nativescript-nfc rfid reader 插件唯一 ID 问题

nativescript-nfc rfid reader plugin unique id issue

我使用 nfc reader 并且我能够获得标签的唯一 ID。当我阅读标签时,id 是这样调用的:

id: [ -52, 22, -61, -67, 80, 1, 4, -32, [length]: 8 ]

如何得到十六进制的?应该叫CC:16:C3:BD:50:01:04:E0。这也是我将拥有数据库条目的方式。所以我取回 id 的方法对我来说毫无用处。

如果有任何有用的回答,我将不胜感激。提前谢谢你。

字节的范围是-128到127

例如对于 Java https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

"byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive)."

您只需将其转换为以十六进制显示的字符串。

通常根据 ISO/IEC 14443-3,UID 是一个 7 字节的数字,其中字节 4 是校验字节的一部分

我不知道如何在 Nativescript 中将字节转换为字符串,但在 Java 中你可以做到


StringBuilder Uid = new StringBuilder();

for (int i = 0; i < result.length; i++) {
                        // byte 4 is a check byte
                        if (i == 3) continue;
                        Uid.append(String.format("%02X ", result[i]));
                    }

虽然跳过校验字节并不是完全需要给你一个唯一的 ID,但这段代码做到了。

对于 Java脚本 How to convert hex string into a bytes array, and a bytes array in the hex string? 应该通过对数组进行类似的迭代来提供答案,将每个字节转换为十六进制字符串