We would like to convert the 12 digit UPC-A to 8 digit UPC-E. Can you tell me which is the best way to do this without having to use my own code to convert?
I got many formula for convert the 8 digit UCC-E to 12 digit UPC-A but not reverse.
We would like to convert the 12 digit UPC-A to 8 digit UPC-E. Can you tell me which is the best way to do this without having to use my own code to convert?
I got many formula for convert the 8 digit UCC-E to 12 digit UPC-A but not reverse.
The algorithm for converting a GTIN-12 identifier between UPC-A and UPC-E representation can be most clearly seen from the following pattern mapping:
SabN0000cdeX ⟺ SabcdeNX : 0≤N≤2
Sabc00000deX ⟺ Sabcde3X
Sabcd00000eX ⟺ Sabcde4X
Sabcde0000NX ⟺ SabcdeNX : 5≤N≤9
In the above S
is the number system, either 0 or 1 and X
is the check digit. If a UPC-A doesn't match a pattern then it cannot be converted to UPC-E.
It can be seen that there may be up to four valid UPC-E representations of each UPC-A:
001200000067 ⟺ 00100627 ⟺ 00120637 ⟺ 00120647 ⟺ 00120067.
Pseudo-code performing one method of conversion from UPC-A to UPC-E looks like this:
Input: A valid twelve-digit UPC-A: Assigned to A[].
Output: PASS: Eight-digit UPC-E representing the UPC-A.
FAIL: Reason.
if A[0] != {0-1} then FAIL: Invalid number system.
if A[3] == {0-2} && A[4..7] == "0000" then PASS: A[0..2] . A[8..10] . A[3] . A[11]
if A[4..8] == "00000" then PASS: A[0..3] . A[9..10] . "3" . A[11]
if A[5..9] == "00000" then PASS: A[0..4] . A[10] . "4" . A[11]
if A[6..9] == "0000" && A[10] == {5-9} then PASS: A[0..5] . A[10] . A[11]
otherwise, FAIL: UPC-A not compatible with UPC-E.