Page 1 of 1

hexatridecimal or base 36

Posted: Thu Feb 07, 2008 4:26 am
by sjordery
Hi All,

Part of a requirement I have is to store a number in hexatridecimal format (also known as base 36). Do you know if there are any built-in functions/routines in DataStage that will allow me to do this... or will it need to be something bespoke? :?

Many thanks in advance.

S

Posted: Thu Feb 07, 2008 7:55 am
by chulett
I would wager you'll need to roll your own conversion.

Before reading this, I thought it was a typo as 3x16 is 48 not 36... so, sexatrigesimal? :lol:

Posted: Thu Feb 07, 2008 8:19 am
by sud
chulett wrote:I would wager you'll need to roll your own conversion.

Before reading this, I thought it was a typo as 3x16 is 48 not 36... so, sexatrigesimal? :lol:
why did you multiply 3 and 16 ? Decimal is base 10, binary is base 2, hexatridecimal or as you correctly pointed sexatrigesimal is base 36(it uses 0-9 and A-Z). Funny names though :lol: :lol:

Posted: Thu Feb 07, 2008 8:28 am
by sjordery
chulett wrote:I would wager you'll need to roll your own conversion.

Before reading this, I thought it was a typo as 3x16 is 48 not 36... so, sexatrigesimal? :lol:
Spot on! :lol:
Wikipedia wrote:The most common latinate name for base 36 seems to be hexatridecimal, although sexatrigesimal would arguably be more correct."
From:

http://en.wikipedia.org/wiki/Base_36

Cheers,
S

Posted: Thu Feb 07, 2008 9:06 am
by sjordery

Code: Select all

chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lenChars = LEN(chars)

;! Check if ok to convert to this base...

If nbase < 2 or nbase > lenChars Then
  Return('')
End 

r = ''
newNumber = ''

;! r contains offset of char that was converted to new base

Loop

  r = MOD(num,nbase)
  newNumber = chars[r+1,1]:newNumber
  num = INT(num/nbase)
  
While num >= nbase Do repeat

;! Final number to convert

Ans = (chars[num+1,1]:newNumber)
This seems to work for me (BASIC routine as I am non-C++!)

Honest critiques welcome :wink:

Regards,
S

Posted: Thu Feb 07, 2008 1:37 pm
by ray.wurlod
There will be some upper limit to the size of numbers you can convert using ordinary arithmetic, depending on your EXACTNUMERIC setting.

For numbers larger than this you can use "string math" (SAdd(), SMui(), SSub() and SDiv() functions). You need to build a "remainder" function out of SDiv() and SSub() functions.

Did you ask WHY there is this requirement?

Posted: Thu Feb 07, 2008 1:56 pm
by chulett
sud wrote:why did you multiply 3 and 16 ?
Simply because 'hexadecimal' is base 16 and then I did the 'tri' or 'triple' or 'times 3' part. :wink:

Posted: Thu Feb 07, 2008 2:08 pm
by shawn_ramsey
I wrote code way back in Foxpro and Oracle to convert both ways (integer to/from binary through hexatridecimal). If I recall it was a pretty simple program.

Hmm... I wonder if I still have it somewhere.

Posted: Fri Feb 08, 2008 3:59 am
by sjordery
ray.wurlod wrote:Did you ask WHY there is this requirement?
The DS process will be replacing an existing process, and these codes are historically stored as base-36. Presume it is just space saving..

Cheers
S

Posted: Fri Feb 08, 2008 4:01 am
by sjordery
ray.wurlod wrote:There will be some upper limit to the size of numbers you can convert using ordinary arithmetic, ...Premium Stuff
Oh - and thanks very much for this Ray. :)

Regards,
S

Posted: Fri Feb 08, 2008 4:36 pm
by sud
chulett wrote:
sud wrote:why did you multiply 3 and 16 ?
Simply because 'hexadecimal' is base 16 and then I did the 'tri' or 'triple' or 'times 3' part. :wink:
Yep but any base conversion is merely positional. There are 0-9 i.e., 10 characters and A-Z 26 more adding to 36 and thats the base 36's significance. The name is 'hexatridecimal' meaning 6(hex) + 3(tri) * 10(decimal) = 36. :roll:

Hexadecimal = 6(hex) + 10(decimal) = 16

Posted: Fri Feb 08, 2008 5:21 pm
by chulett
Wow... you guys are way too anal. Did you not notice Mr Winkie? You know, as in 'wink, wink, nudge, nudge'.

Posted: Mon Feb 11, 2008 8:44 am
by sud
chulett wrote:Wow... you guys are way too anal. Did you not notice Mr Winkie? You know, as in 'wink, wink, nudge, nudge'.
Lest anyone misunderstands, Craig, one of our most valuable posters, means anal as in analytical. :wink:

Posted: Mon Feb 11, 2008 8:59 am
by chulett
:lol: Umm... yah! That's exactly what I meant.