Convertisseur RFID

Outil de conversion entre SGTIN-96 (RFID Hex) et Code-barres (GTIN) + Numéro de Série. Compatible avec les lecteurs RFID standards comme Zebra, Chainway, Impinj, Nextwaves.

Convertisseur RFID

Logique de Code

// 1. Binary Conversion

src = bin(0x) // = "?"

// 2. Extract Fields (Bit Slice)

header = src[0:8] → "00110000""?" (?)
filter = src[8:11] → "..."?
partition = src[11:14] → "..."?

// 3. Determine Partition Rule (Partition ?)

rule = PARTITIONS[?]
// Company Bits: ?, Item Bits: ?

// 4. Extract Company & Item

company = src[14:14] → "..."?
itemRef = src[14:14] → "..."?
serial = src[14:96] → "..."?

Code Développeur

Utilisez cette logique dans votre projet.

1// TypeScript / JavaScript SGTIN-96 Utils
2
3export const GS1_PARTITION_TABLE = [
4  { value: 0, partition: 0, companyPrefixBits: 40, itemReferenceBits: 4, companyDigits: 12, itemDigits: 1 },
5  { value: 1, partition: 1, companyPrefixBits: 37, itemReferenceBits: 7, companyDigits: 11, itemDigits: 2 },
6  { value: 2, partition: 2, companyPrefixBits: 34, itemReferenceBits: 10, companyDigits: 10, itemDigits: 3 },
7  { value: 3, partition: 3, companyPrefixBits: 30, itemReferenceBits: 14, companyDigits: 9, itemDigits: 4 },
8  { value: 4, partition: 4, companyPrefixBits: 27, itemReferenceBits: 17, companyDigits: 8, itemDigits: 5 },
9  { value: 5, partition: 5, companyPrefixBits: 24, itemReferenceBits: 20, companyDigits: 7, itemDigits: 6 },
10  { value: 6, partition: 6, companyPrefixBits: 20, itemReferenceBits: 24, companyDigits: 6, itemDigits: 7 },
11];
12
13export function encodeSgtin96(gtin: string, serial: string, filter: number) {
14  gtin = gtin.padStart(14, "0");
15  const p = GS1_PARTITION_TABLE.find(rule => {
16    const cp = parseInt(gtin.slice(1, 1 + rule.companyDigits));
17    const ir = parseInt(gtin[0] + gtin.slice(1 + rule.companyDigits, 13));
18    return cp < (1 << rule.companyPrefixBits) && ir < (1 << rule.itemReferenceBits);
19  });
20  if (!p) throw new Error("Invalid GTIN for SGTIN-96");
21
22  const cpVal = parseInt(gtin.slice(1, 1 + p.companyDigits));
23  const irVal = parseInt(gtin[0] + gtin.slice(1 + p.companyDigits, 13));
24  
25  let b = (0x30).toString(2).padStart(8,"0");
26  b += filter.toString(2).padStart(3,"0");
27  b += p.partition.toString(2).padStart(3,"0");
28  b += cpVal.toString(2).padStart(p.companyPrefixBits,"0");
29  b += irVal.toString(2).padStart(p.itemReferenceBits,"0");
30  b += parseInt(serial).toString(2).padStart(38,"0");
31  return binaryToHex(b);
32}
33
34export function decodeSgtin96(hex: string) {
35  const b = hexToBinary(hex);
36  const pVal = parseInt(b.substring(11, 14), 2);
37  const rule = GS1_PARTITION_TABLE.find(r => r.partition === pVal);
38  if (!rule) throw new Error("Invalid Partition");
39
40  const cp = parseInt(b.substring(14, 14 + rule.companyPrefixBits), 2);
41  const ir = parseInt(b.substring(14 + rule.companyPrefixBits, 14 + rule.companyPrefixBits + rule.itemReferenceBits), 2);
42  const serial = parseInt(b.substring(14 + rule.companyPrefixBits + rule.itemReferenceBits, 96), 2);
43
44  const cpStr = cp.toString().padStart(rule.companyDigits, "0");
45  const irStr = ir.toString().padStart(rule.itemDigits, "0");
46  const gtinCore = irStr[0] + cpStr + irStr.substring(1);
47
48  // Check digit calculation
49  let sum = 0;
50  for (let i = 0; i < 13; i++) {
51    sum += parseInt(gtinCore[i]) * (i % 2 === 0 ? 3 : 1);
52  }
53  const check = (10 - (sum % 10)) % 10;
54  
55  return {
56    gtin: gtinCore + check,
57    serial: serial.toString()
58  };
59}
60
61function binaryToHex(b: string) {
62  let hex = "";
63  for (let i = 0; i < b.length; i += 4) {
64    hex += parseInt(b.substring(i, i + 4), 2).toString(16).toUpperCase();
65  }
66  return hex;
67}
68
69function hexToBinary(h: string) {
70  let bin = "";
71  for (let i = 0; i < h.length; i++) {
72    bin += parseInt(h[i], 16).toString(2).padStart(4, "0");
73  }
74  return bin;
75}

Comment ça marche

Comprendre SGTIN

Relation entre GTIN et EPC.

Diagramme SGTIN

Structure SGTIN-96

HDR
FLT
PRT
COMPANY
ITEM
SERIAL (38)

Analyse Détaillée

En-têteBits 0-8 (8)
00110000

Préfixe standard.

FiltreBits 8-11 (3)
...

Type d'objet.

PartitionBits 11-14 (3)
...

Application des règles de partition.

Préfixe EntrepriseBits 14-0 (0)
...

Code entreprise GS1.

Référence ArticleBits 0-0 (0)
...

Code produit.

Numéro de SérieBits 0-96 (38)
...

Identifiant unique.

Logique d'Encodage

  1. Pad GTIN-13.
  2. Split GTIN-14.
  3. Convertir en Binaire.
  4. Concaténer.

Guide de Référence

FValeurs de Filtre

ValeurDescription
0
Tous les autres
Usage général.
1
Point de Vente
Unité consommateur.
2
Caisse Complète
Unité d'expédition.
3
Réservé
Réservé.
4
Paquet Intérieur
Groupe sous-caisse.
5
Réservé
Réservé.
6
Palette
Unité logistique.
7
Composant
Composant interne.

PTable de Partition

Valeur
Préfixe Entreprise
(Bits / Chiffres)
Réf. Article
(Bits / Chiffres)
040 / 124 / 1
137 / 117 / 2
234 / 1010 / 3
330 / 914 / 4
427 / 817 / 5
524 / 720 / 6
620 / 624 / 7

FAQ