Converting GUIDs to base-36

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vector

    Converting GUIDs to base-36

    I've got an application that generates GUIDs. A lot of GUIDs. Lots
    of GUIDs that end up in files on disk, taking up space. I'd like to
    continue using the Guid.NewGuid() function as my unique tag generator,
    but I'd also like to compress them to base 36 strings, which should
    retain their uniqueness but save me disk space. I've looked at
    various base conversion functions, and haven't found a suitable one.
    Further, I don't need an AnyBase converter. I need a very specific
    thing: a base-16 string to base-36 string converter. Anything
    additional would be a waste. Can somebody help me fill in the blanks
    below?

    static string MakeGuid36()
    {
    //make a new guid
    Guid g = Guid.NewGuid();

    //convert the guid to a base-16 string
    string strGuid = g.ToString().Re place("-", "");

    //convert the base-16 string to a base-36 string
    ??

    //return the result
    return strGuid;
    }
  • D. Rush

    #2
    Re: Converting GUIDs to base-36

    Here's some C code to do what you want. You'll have to write a function to
    handle 'words' but this is a fast way to do the character level conversion:

    /*************** *************** *************** *************** ***************
    *
    return a base 36 character. v must be from 0 to 35.
    *************** *************** *************** *************** *************** *
    /
    static char base36(unsigned int v)
    {
    static char basechars[] = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
    return basechars[v % 36];
    }

    You can see the whole file here:


    "vector" <isbat1@yahoo.c om> wrote in message
    news:7961e1f9.0 410041036.430cd 903@posting.goo gle.com...[color=blue]
    > I've got an application that generates GUIDs. A lot of GUIDs. Lots
    > of GUIDs that end up in files on disk, taking up space. I'd like to
    > continue using the Guid.NewGuid() function as my unique tag generator,
    > but I'd also like to compress them to base 36 strings, which should
    > retain their uniqueness but save me disk space. I've looked at
    > various base conversion functions, and haven't found a suitable one.
    > Further, I don't need an AnyBase converter. I need a very specific
    > thing: a base-16 string to base-36 string converter. Anything
    > additional would be a waste. Can somebody help me fill in the blanks
    > below?
    >
    > static string MakeGuid36()
    > {
    > //make a new guid
    > Guid g = Guid.NewGuid();
    >
    > //convert the guid to a base-16 string
    > string strGuid = g.ToString().Re place("-", "");
    >
    > //convert the base-16 string to a base-36 string
    > ??
    >
    > //return the result
    > return strGuid;
    > }[/color]


    Comment

    Working...