hexatridecimal or base 36

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

hexatridecimal or base 36

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Post 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:
It took me fifteen years to discover I had no talent for ETL, but I couldn't give it up because by that time I was too famous.
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post 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
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
shawn_ramsey
Participant
Posts: 145
Joined: Fri May 02, 2003 9:59 am
Location: Seattle, Washington. USA

Post 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.
Shawn Ramsey

"It is a mistake to think you can solve any major problems just with potatoes."
-- Douglas Adams
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post 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
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post 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
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Post 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
It took me fifteen years to discover I had no talent for ETL, but I couldn't give it up because by that time I was too famous.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Wow... you guys are way too anal. Did you not notice Mr Winkie? You know, as in 'wink, wink, nudge, nudge'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Post 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:
It took me fifteen years to discover I had no talent for ETL, but I couldn't give it up because by that time I was too famous.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:lol: Umm... yah! That's exactly what I meant.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply