Compressed GUID barcode in C#

imagesI have worked with barcode today but I have the problem: I need to print on barcode a GUID. GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {F00DFACE-FEED-DEAD-BEEF-C0FFEEDECADE}; this post is not a tutorial about GUID (You can find information on wikipedia).

The most suitable 2D barcode to hold random data, and GUIDs is probably Code128.
you need to give a string to make a Code128 barcode. However to use the typical hexadecimal string representation is too costly. That would use only 16 (2^4) values for each code instead  of the 128 (2^7) theoretically possible (see below) with Code128.

So theoretically at least a 7/4 longer barcode.
Code128 can encode the 128 characters basic ASCII set but there is a trick here. To do so, Code128 use 2 code sets (96 characters capable each): 128A and 128B (there is also a third code set for numbers). And to switch the code set as a cost! It costs 1 code. Your barcode might end up almost the same size as string encoded (The length is variable and random: it depends on how many times the code set has to be switched).
Your data must therefore be modulated by 96 for each code, and you will get the smallest guid barcode possible. See the code below. There is also the 128 modulation methods if you want to play with variable length barcodes.

I made a static class where I compress the guid before to print. The sample project with the class is on GITHUB repository

To generate the barecode I used a codeprojects project: BARCODE GENERATOR  but there are a lot of bare code generators on internet.


One thought on “Compressed GUID barcode in C#


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...