I am developing an Android NFC application. This application can scan an NFC tag (here I have an NXP NTAG 5 boost tag, which is an NFC Forum Type 5 tag).
Since the UID of the NFC-V tag is reversed, my goal is to display the (re)reversed UID of the NFC tag, where each byte is separated by two dots.
Below is the method I use to do this. It reverses the UID well and converts it to hexadecimal well but I can't figure out how to insert a ":" separator every other character.
fun byteArrayToHexInversed(bytes: ByteArray): String {
//First reverse the UID
bytes.reverse()
//Then convert byteArray to Hexa
val hexChars = CharArray(bytes.size * 2)
for (j in bytes.indices) {
val v = bytes[j].toInt() and 0xFF
hexChars[j * 2] = hexArray[v ushr 4]
hexChars[j * 2 + 1] = hexArray[v and 0x0F]
}
//Finally return the String with the separators
return hexChars.joinToString(":") { byte ->
byte.toString().padStart(2, '0')
}
}
Here is what I have in input:
000839CB580104E0
Here is what I want in output:
E0:04:01:58:CB:39:08:00