# Upc ean convert

`upc-ean-convert` · version 1.0.0 · Identifiers & check digits · free, no key needed

Convert a validated UPC-A, UPC-E, EAN-13 or GTIN-14 number to another symbol format, recomputing the check digit.

**Use when you need to: convert upc-e to upc-a · expand a compressed upc barcode · convert ean-13 to gtin-14.**

## Decide before calling

Read the [versioned contract](/v1/tools/upc-ean-convert/versions/1.0.0) and the supported scope below. Reuse `upc-ean-convert@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `upc-ean-convert@1.0.0` for convert upc-e to upc-a. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- convert upc-e to upc-a
- expand a compressed upc barcode
- convert ean-13 to gtin-14
- compress a upc-a to upc-e
- upc to ean converter
- pad a barcode number to gtin-14

## Not supported

- validating a key and reporting its GS1 prefix meaning (use gs1-key-validate)
- parsing a GS1 AI element string (use gs1-element-string-parse)
- converting to or from EAN-8 or ISBN Bookland forms

## Behavior

- value is taken exactly as given; no trimming. from_format is chosen by value.length: 8 -> upc-e, 12 -> upc-a, 13 -> ean-13, 14 -> gtin-14; any other length, a non-digit character, or a mismatched source check digit throws invalid_input.
- upc-e source: value[0] (number system) must be '0' or '1'; the 6-digit body is expanded to an 11-digit UPC-A payload by its last digit's pattern (0-2, 3, 4, or 5-9), then its GS1 mod-10 check digit is verified against value[7].
- upc-a/ean-13/gtin-14 source: value's own trailing GS1 mod-10 check digit is verified over the whole value.
- The canonical GTIN-14 form is always computed first (left-zero-padding upc-a/ean-13, or expanding upc-e through UPC-A); to selects the output: gtin-14 returns it unchanged; ean-13/upc-a/upc-e each throw not_computable if the leading indicator digit(s) that would be dropped are non-zero, or, for upc-e, if the UPC-A number system is not 0/1 or none of the 4 zero-suppression patterns (checked in order, first match wins) apply.
- check_digit is always the last character of result. Pure string parsing and GS1 mod-10 arithmetic; no locale, clock, or randomness.

## Input

- `value` (string, required): min length 1; max length 14
- `to` (one of "upc-a", "upc-e", "ean-13", "gtin-14", required)

## Output

- `result` (string, required): min length 8; max length 14
- `from_format` (one of "upc-a", "upc-e", "ean-13", "gtin-14", required)
- `check_digit` (string, required): pattern `^[0-9]$`

## Limits

- max value bytes: 14

## Example

Request input:

```json
{
  "value": "042100005264",
  "to": "upc-e"
}
```

Response:

```json
{
  "result": {
    "result": "04252614",
    "from_format": "upc-a",
    "check_digit": "4"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "upc-ean-convert",
  "version": "1.0.0",
  "input": {
    "value": "042100005264",
    "to": "upc-e"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/upc-ean-convert/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"value":"042100005264","to":"upc-e"}'
```

The machine-readable contract is at [/v1/tools/upc-ean-convert/versions/1.0.0](/v1/tools/upc-ean-convert/versions/1.0.0).

### CLI

```sh
node cli.mjs run upc-ean-convert 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Issn validate](/tools/issn-validate): Validate an 8-digit ISSN's mod 11 check digit (X allowed) and compute its 977-prefixed EAN-13 barcode form.
- [Isin compute from nsin](/tools/isin-compute-from-nsin): Build a 12-character ISIN from a country prefix and a CUSIP/SEDOL national number, computing its Luhn check digit.
- [Cn resident id parse](/tools/cn-resident-id-parse): Parse an 18-digit (or legacy 15-digit) Chinese resident ID: region code, birth date, sex and GB 11643-1999 check digit.
- [Gs1 key validate](/tools/gs1-key-validate): Validate a GTIN-8/12/13/14, GLN, SSCC or GSIN's GS1 mod-10 check digit and look up its 3-digit GS1 prefix meaning.
- [Iban compute from bban](/tools/iban-compute-from-bban): Compute the MOD 97-10 check digits and full IBAN for a country code and BBAN, using the pinned IBAN registry.
- [Isbn validate](/tools/isbn-validate): Validate an ISBN-10 (mod 11, X allowed) or ISBN-13 (EAN mod 10) check digit and return the other form when it exists.
