Differentiate between UPC-E and EAN-8 in Swift

Mac*_*ina 5 barcode-scanner swift

Regarding barcodes, UPC-E and EAN-8 have the same amount of digits. (8)

When I scan a barcode, I have to remove the check-digit. I have to remove it to match with the barcode in the database.

How can I differentiate between these two? With my other barcodes, I differentiate based on digit length and remove the last digit, but for these two I can't because they're both 8 digits and only 1 needs to have the check digits removed

  • EAN-8's check digit does not need to be removed

  • UPC-E's check digit is character index 7 (last digit) needs to be removed as well as the number system character at index 0 (first digit).

有没有一种方法可以根据校验位算法进行区分,或者......

pic*_*ano 5

我不认为你总是可以。EAN-8 和 UPC-E 具有不同的校验和机制。对于 UPC-E,您首先扩展到 UPC-A,然后计算校验和。对于 EAN-8,您只需使用前 7 位数字。如果校验位仅对 EAN-8 或 UPC-E 有效,那么您已得到答案。但如果两者都匹配(我相信这可能会发生),那么你无法仅根据数字来确定它是 EAN8 还是 UPCE。


Rei*_*ica 1

我认为这个问题与 Swift 根本无关。我推测条形码扫描仪是通过 USB 端口连接的。扫描仪可能伪装成键盘并“输入”解码后的数据。您需要参考扫描仪的文档来了解如何重新配置​​扫描仪以提供除解码数据之外的诊断数据。诊断将包括条形码的类型。

作为解决方法,您可以删除最后一个数字,尝试数据库查找,如果失败,请删除第一个数字并再次尝试查找。