Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAN8 to EPC and EPC to EAN8 produces different results #2

Closed
dim2k2006 opened this issue Feb 18, 2022 · 7 comments
Closed

EAN8 to EPC and EPC to EAN8 produces different results #2

dim2k2006 opened this issue Feb 18, 2022 · 7 comments

Comments

@dim2k2006
Copy link

As far as I understand if I encode EAN8 value to EPC and then decode this EPC back to EAN I should get the original EAN value but this never happens.

Example of code:

`
const epcToEan = (epc: string): string => {
const data = tds.valueOf(epc);

const result = data.toBarcode() as string;

return result;
};

const eanToEpc = (ean: string): string => {
const epc = new tds.Sgtin96().setGtin(ean);

return epc.toHexString();
};

console.log('eanToEpc -> epcToEan:', epcToEan(eanToEpc('60573421')));
`

I was expecting to receive 60573421 as a result but I receive 60000005734216.

What am I doing wrong?

@sergiss
Copy link
Owner

sergiss commented Feb 18, 2022

Hi Dmitry,

Thanks for your input.

GS1 documentation indicates that a GTIN must have 14 digits, so the user must fill in with leading zeros.

Try this:

console.log('eanToEpc -> epcToEan:', epcToEan(eanToEpc('00000060573421')));

Or modify your eanToEpc method, like this:

const eanToEpc = (ean: string): string => {
const epc = new tds.Sgtin96().setGtin(ean.padStart(14,"0"));
return epc.toHexString();
}

You can also use this GS1 web app to perform checks:

https://www.gs1.org/services/epc-encoderdecoder

Best regards.

Sergi

@dim2k2006
Copy link
Author

Aha, and then when I receive a result from RFID device (which is EPC) and extract EAN from it, I can safely remove all leading zeros from this EAN?

@sergiss
Copy link
Owner

sergiss commented Feb 18, 2022

Yes, you can remove them, but if you want to use a standard later (GTIN-8, GTIN-12, GTIN-14), you will have to control the number of digits.

@dim2k2006
Copy link
Author

Got it, thank you so much for the library and for the information!)

@dim2k2006
Copy link
Author

Hello,

I use the same logic ean -> epc -> ean and seems like there is something wrong with some ean numbers:

original ean: 00000074018029. decoded ean: 00000074018024. epc: 30000001C3C5280000000000
original ean: 00000045214445. decoded ean: 00000045214448. epc: 3000000113F7900000000000
original ean: 00000028225773. decoded ean: 00000028225775. epc: 30000000AC46C40000000000

The last digit in decoded ean differs from the original ean number.

What could be the reason for such behavior?

@sergiss
Copy link
Owner

sergiss commented Mar 9, 2022

Hello Dmitry,
The EAN codes you are using have the wrong control code. For example, the ean 0000007401802(4) has 4 as check digit.
Greetings.

@dim2k2006
Copy link
Author

I checked all the above eans here https://www.gs1.ch/en/home/offer/barcode/check-digit-calculator-and-ean-13-barcode-generator and yes all of them have the wrong check digit. Thank you so much for pointing it out!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants