Skip to main content
Email Password   helpLost your password?

Introduction

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!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralBase 30 Derivative Class Pin
Tyler Jensen
14:48 24 Nov '08  
GeneralI can't find the Exception Classes in the source code Pin
james.wren
6:54 30 Jun '08  
GeneralRe: I can't find the Exception Classes in the source code Pin
Steve Barker 333
13:17 30 Jun '08  
GeneralRe: I can't find the Exception Classes in the source code Pin
Steve Barker 333
13:26 30 Jun '08  
GeneralTesting Code for Base36ToUInt64() Pin
Russell Mangel
23:00 23 Mar '06  
GeneralTesting Code for UInt64ToBase36() Pin
Russell Mangel
22:55 23 Mar '06  
GeneralHere is my version of Base36 Pin
Russell Mangel
22:53 23 Mar '06  
GeneralRe: Here is my version of Base36 Pin
samyu1*
6:57 23 Jun '09  
GeneralRe: Here is my version of Base36 Pin
Steve Barker 333
12:46 24 Jun '09  
GeneralRe: Here is my version of Base36 Pin
samyu1*
4:48 25 Jun '09  
GeneralRe: Here is my version of Base36 Pin
Steve Barker 333
7:21 25 Jun '09  
Generalwhat about this... Pin
Jeremy Falcon
10:46 8 Jun '05  
GeneralRe: what about this... Pin
Steve Barker 333
5:30 12 Jun '05  
GeneralRe: what about this... Pin
Jeremy Falcon
16:35 12 Jun '05  
GeneralFantastic! Pin
GeminiMan
18:41 7 Jun '05  
GeneralRe: Fantastic! Pin
tupacs01
5:50 8 Jun '05  
GeneralRe: Fantastic! Pin
umuhk
9:47 8 Jun '05  
GeneralRe: Fantastic! Pin
Keith Farmer
9:55 8 Jun '05  
GeneralRe: Fantastic! Pin
Steve Barker 333
5:34 12 Jun '05  
GeneralRe: Fantastic! Pin
tupacs01
9:03 12 Jun '05  
GeneralRe: Fantastic! Pin
Jeremy Falcon
10:51 8 Jun '05  
GeneralRe: Fantastic! Pin
GeminiMan
10:56 8 Jun '05  
GeneralRe: Fantastic! Pin
tupacs01
11:04 8 Jun '05  
GeneralRe: Fantastic! Pin
Jeremy Falcon
4:27 9 Jun '05  
GeneralRe: Fantastic! Pin
GeminiMan
5:22 9 Jun '05  


Last Updated 7 Jun 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009