Data Packing

I was doing some random experiments using assembly and C. This is a simple example in packing 2 numbers inside a register in assembly. Let’s assume

$latex al < 2^{5}&bg=232225&fg=bbbbbb&s=4$
$latex bl < 2^{3}&bg=232225&fg=bbbbbb&s=4$

We want to store these 2 values inside the dl register. The dl register is of 8 bits, so 5 + 3 = 8 bits

Packing

Unpacking

After experimenting with this I thought of coding a high level version of this using C. In here we pack and unpack a DWORD and a short inside a DWORD64 variable and build a string value and again unpack the DWORD64 value back to their original variables with the original values.

Leave a Reply