💾 Archived View for gemini.robrohan.com › 2009-02-14-compressing-a-uuid.md captured on 2022-04-28 at 17:29:12. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

---

author: rob

comments: true

date: 2009-02-14 08:19:56+00:00

slug: compressing-a-uuid

title: Compressing A UUID

---

[FarCry](http://farcrycore.org) makes heavy use of UUIDs. I am a fan of UUIDs myself, but in some instances they are a bit long. It seems like there should be a way to make them shorter and still have them hold their value. I had a need for a shorter UUID and set out to find a way to compress a UUID.

It kind of worked. It wont work for my purposes so it was a wash for me, but it was still quite a bit of fun and I figured I might as well get a blog post out of all the work.

My example UUID: ED11C880-FA56-11DD-A604001EC203A3AD

After looking at it for a while, it dawned on me that all the characters are hex values... which means each value can only have 16 values... which means you should be able to fit it into 4 bits. If that's the case, then (after the 3 dashes are removed), it should be possible to reduce the UUID by 50%.

First I set up a simple table to look up each value. Basically just:

![Picture 1-7](/wp-content/uploads/2009/02/picture-1-7.png)

Then I wrote a simple loop that grabbed two chars at a time from the UUID, looked up their value in the Hex table, and then set the lower order bits to the first char, and the higher order bits to the second char. This table is an output from the loop:

![Picture 2-3](/wp-content/uploads/2009/02/picture-2-3.png)

As you can see the 8 bits of output (far right) is the binary representation of the integer index to 2 of the actual Hex values.

It does indeed work, hooray!

Going in reverse, looping over eight bits at a time, breaking them into 4 bits, turning them into integers and then looking up the proper Hex value works equally well (as you would expect)

![Picture 3-2](/wp-content/uploads/2009/02/picture-3-2.png)

The reason this is a failure for me is that there doesn't appear to be a way to pass this information in the URL. If you were to just look at this string, it would be gobbledygook since it has high ASCII and non-printable characters. It looks like this actually:

![Picture 4](/wp-content/uploads/2009/02/picture-4.png)

There are only 3 ways I can think of to pass data like this in the url

1. Hex encode - that results in the exact same string I started out with :-/

2. URL encoded - makes the output way longer than just the UUID by itself.

3. base64 - Humorously makes the string the same length as the UUID (MMOeEcKMCMKvZRHDnWpAw6EsMDrDmg==).

So... the whole thing was a "waste of time" (unless you have any suggestions).

It was fun to have my theory work out, but it was quite a let down that it's completely useless for my needs.