473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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().Replace("-", "");

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

//return the result
return strGuid;
}
Nov 16 '05 #1
1 10850
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[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return basechars[v % 36];
}

You can see the whole file here:
http://www.koders.com/c/fidAE1343A83....aspx?s=base36

"vector" <is****@yahoo.com> wrote in message
news:79**************************@posting.google.c om...
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().Replace("-", "");

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

//return the result
return strGuid;
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shaun Clark | last post by:
Hello, I am trying to bring my entire organization from a Microsoft platform to a Linux one, starting with all of the servers we are currently running. Sun ONE ASP allows me to run ASP on Linux...
14
by: David Wheeler | last post by:
Hi All, I want to use GUIDs for object IDs in my application. This means that they would be used for primary keys in PostgreSQL, and there would of course be FKs pointing to them. A GUID is 128...
4
by: J.Marsch | last post by:
I notice that when I generate various guids, they appear to have a mix of upper and lowercase letters. Is the uniqueness of a guid case-sensitive? In other words, if I generate a guid, and...
11
by: Jeff | last post by:
Hi - I'm experiencing a strange problem when comparing 2 guids. In my trial, they're not equal. When I step through the (VB.NET) code, they are evaluated as equal, and when I enter the...
2
by: Howard Kaikow | last post by:
Being lazy, I sometimes copy a project to another directory, then tweak the code. A problem arises because then both projects have identical GUIDs in the .sln file, and in the assembly file. ...
3
by: Michael | last post by:
Hi All, I need a little help converting a class to vb.net. I have the following to convert: internal class BBBSDIForm : BBBForm { public BBBSDIForm(FormInfo fi, FormMgr formMgr) : base(fi,...
3
by: dew | last post by:
I have a stored procedure that retrieves the id of a client table, which is a guid To get that id, I have dim clientid as guid = GetClientID("OrgName") The GetClientID returns a string,...
13
by: Paraic Gallagher | last post by:
Hi, This is my first post to the list, I hope somebody can help me with this problem. Apologies if it has been posted before but I have been internet searching to no avail. What I am trying...
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
2
by: Alex Buell | last post by:
Is there an elegant way of converting strings containing digits between different number bases in C++? I.e.: 10 (base 2) = 2 (base 10) FF (base 16) = 256 (base 10) F (base 16) = 1111 (base 2)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.