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?
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?
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
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.
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++!)
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.
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
Simply because 'hexadecimal' is base 16 and then I did the 'tri' or 'triple' or 'times 3' part.
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.
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.