Click here to Skip to main content
11,932,402 members (49,600 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked

Base 36 type for .NET (C#)

, 7 Jun 2005
Rate this:
Please Sign up or sign in to vote.
A struct that provides base-36 functionality.


I found myself wanting to express a whole host of numbers in as few characters as possible. I came up with the idea of using a Base36 type to represent Base 36 numbers. This scheme is basically an extension to hexadecimal, but whereas hexadecimal stops at 15 (F), Base 36 carries on, with G being 16, all the way up to Z, which is 35. 10 in Base 36 is in fact 36 in Base 10. Base 36 has the benefit that the "numbers" are expressed by characters that are readable to humans, so this can be a good way of passing numerical data over the telephone for instance. Using Base 36, numbers up to 46,655 can be expressed using only 3 characters (ZZZ).

The Code

The code for my Base36 struct is extremely simple, so I won't go into details explaining it; download it and take a look. I've overloaded as many operators as I could, so Base 36 numbers can be added, subtracted, multiplied etc... I've tried to keep the methods of my struct consistent with the way that Microsoft labels type methods. You can instantiate a Base 36 "number" in string format, or from a standard Base 10 number:

Base36 b1 = 104;
//This has the value 104 in base 10.

Base36 b2 = "DSGFDFDZ434";
//This has the value 50,420,080,957,151,344 in Base 10.

The source files should be made into a class library. The demo project should be made into a console application, with a reference added to the class library; this demonstrates my struct in action!

And that's it! The struct seems to work very well, although I'm sure some of the code can be optimised. Good luck!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Steve Barker 333
Web Developer
United Kingdom United Kingdom
I left Nottingham University in 2000 with an MSci in Mathematical Physics proudly in my grasp... but not a clue what I wanted to do with it!

Somewhere along the way however, I managed to swap Quantum Mechanics and General Relativity for RecordSets and Arrays, and took on some freelance VB development work. I soon realised I'd found my vocation, and promptly found an IT post in Nottingham, where I began developing Access databases (using VBA) for local government offices.

At some point I moved from Access to SQL Server, and before long, got my grubby palms on a copy of Visual Studio .NET. A very important milestone in my development career I think! Armed with my new found .NET knowledge, and with four years IT experience under my belt, I found my second job as Project Manager/IT Systems Developer, which brings us nicely up to date. I now work almost exclusively in .NET, writing mainly C# Windows applications and the odd web service, although I’m working on my ASP.NET too: the future of software development.

You may also be interested in...

Comments and Discussions

QuestionLicense of this code Pin
hugob12311-Sep-13 0:18
memberhugob12311-Sep-13 0:18 
AnswerRe: License of this code Pin
Steve Barker 33311-Sep-13 10:57
memberSteve Barker 33311-Sep-13 10:57 
GeneralGreat Stuff! Pin
mikemkii14-Oct-11 6:06
membermikemkii14-Oct-11 6:06 
GeneralBase 30 Derivative Class Pin
Tyler Jensen24-Nov-08 14:48
memberTyler Jensen24-Nov-08 14:48 
GeneralI can't find the Exception Classes in the source code Pin
james.wren30-Jun-08 6:54
memberjames.wren30-Jun-08 6:54 
The Source code won't compile because it doesn't find the exception classes. Am I missing something?
GeneralRe: I can't find the Exception Classes in the source code Pin
Steve Barker 33330-Jun-08 13:17
memberSteve Barker 33330-Jun-08 13:17 
GeneralRe: I can't find the Exception Classes in the source code Pin
Steve Barker 33330-Jun-08 13:26
memberSteve Barker 33330-Jun-08 13:26 
GeneralRe: I can't find the Exception Classes in the source code Pin
jweinraub16-Mar-11 7:10
memberjweinraub16-Mar-11 7:10 
GeneralTesting Code for Base36ToUInt64() Pin
Russell Mangel23-Mar-06 23:00
memberRussell Mangel23-Mar-06 23:00 
GeneralTesting Code for UInt64ToBase36() Pin
Russell Mangel23-Mar-06 22:55
memberRussell Mangel23-Mar-06 22:55 
GeneralHere is my version of Base36 Pin
Russell Mangel23-Mar-06 22:53
memberRussell Mangel23-Mar-06 22:53 
GeneralRe: Here is my version of Base36 Pin
samyu1*23-Jun-09 6:57
membersamyu1*23-Jun-09 6:57 
GeneralRe: Here is my version of Base36 Pin
Steve Barker 33324-Jun-09 12:46
memberSteve Barker 33324-Jun-09 12:46 
GeneralRe: Here is my version of Base36 Pin
samyu1*25-Jun-09 4:48
membersamyu1*25-Jun-09 4:48 
GeneralRe: Here is my version of Base36 Pin
Steve Barker 33325-Jun-09 7:21
memberSteve Barker 33325-Jun-09 7:21 
Questionwhat about this... Pin
Jeremy Falcon8-Jun-05 10:46
memberJeremy Falcon8-Jun-05 10:46 
AnswerRe: what about this... Pin
Steve Barker 33312-Jun-05 5:30
memberSteve Barker 33312-Jun-05 5:30 
GeneralRe: what about this... Pin
Jeremy Falcon12-Jun-05 16:35
memberJeremy Falcon12-Jun-05 16:35 
GeneralFantastic! Pin
GeminiMan7-Jun-05 18:41
memberGeminiMan7-Jun-05 18:41 
GeneralRe: Fantastic! Pin
tupacs018-Jun-05 5:50
membertupacs018-Jun-05 5:50 
GeneralRe: Fantastic! Pin
umuhk8-Jun-05 9:47
memberumuhk8-Jun-05 9:47 
GeneralRe: Fantastic! Pin
Keith Farmer8-Jun-05 9:55
memberKeith Farmer8-Jun-05 9:55 
GeneralRe: Fantastic! Pin
Steve Barker 33312-Jun-05 5:34
memberSteve Barker 33312-Jun-05 5:34 
GeneralRe: Fantastic! Pin
tupacs0112-Jun-05 9:03
membertupacs0112-Jun-05 9:03 
GeneralRe: Fantastic! Pin
Jeremy Falcon8-Jun-05 10:51
memberJeremy Falcon8-Jun-05 10:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 7 Jun 2005
Article Copyright 2005 by Steve Barker 333
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid