We produce Mifare EV1 RFID tags and need to convert the UID to a seven-digit code printed on a wristband. Does anyone have a formula to convert the UID to a seven-digit code using numbers and letters?
I reached out to Hal Casey, the director of AIT, IUID and joint solutions for the U.S. Navy, for an answer to your question. Hal has a few questions of his own for you:
• Why a seven-digit code? Why not an eight-digit code or 12-digit?
• Why not just print the UID?
• Why not print a bar code (2D pdf417 or data-matrix)?
• Have you read AN10927 on Mifare and UID handling? It offers sample code for interpreting UIDs.
Now, on to his answer:
Conversions would entail knowing if the question is for the Mifare Classic or Mifare Ultralight (i.e. whether you are dealing with a four-, seven-or 10-byte format).
The formula would entail picking a base (binary = base 2, decimal = base 10, hexadecimal = base 16) and programing a conversion equation. Mifare UIDs would, therefore, convert as follows:
• an eight-digit number if the UID has four bytes
• a 14-digit number if the UID has seven bytes
As Mifare Ultralight UIDs (or any seven-byte UIDs) have the form 0x04xxxxxxxxxxxx, converting this to a decimal number would give a maximum a 16-digit number (0x04FFFFFFFFFFFF = 1407374883553279). However, converting a four-byte UID to decimal would still not result in a seven-digit number. Adding all letters back in, the logical approach for printing the UID in a seven-alpha-numeric field would be to go the other way—taking the HEX UID and converting it to a higher base.
Increasing the base (base 36) would reduce the number of digits for a Mifare Ultralight format, but even then, the reduction is down to 10 characters (Hex FFFFFFFFFFFF = Base-32 7vvvvvvvvv). The next step would be to use a BAMS conversion (i.e. mirror the field across the zero point). This doubles the range of numbers but keeps the character count down. One character is sacrificed for the plus-minus symbol, leaving six for the data.
An alternative would be to increase the base of the calculation, remembering that all bases, from base 2 to base 36, are case-insensitive (e.g., A = a), while from base 37 to base 64, numbers are case-sensitive (e.g., A!= a). A = decimal 10, whereas a = decimal 36. Add special characters, and the base can go higher. I hope this helps.
—Mark Roberti, Founder and Editor, RFID Journal
At What Distance Can I Kill an RFID Tag? »