Hi all,
We are looking for a function that converts base 10 numbers to base 36 numbers (using numbers and letters to represent base 36 numbers), and also another function to convert base 36 text
Example1 - Convert base 10 to base 36 >> enter base 10 number int(3634) and get base 36 text string "2SY"
Example2 - Convert base 36 to base 10 >> enter base 36 text string("A2J") and get base 10 number int 13051
Does anyone have an idea where we can start from?
Thanks
Discussion posts and replies are publicly visible
Also since it was bugging me, I went ahead and created the "convert back to base 10" expression rule, which takes any positive baseX value (between base 2 and base 36), along with the specific base in question. Note it does minimal error handling but probably can't handle extended corner cases.
if( or( isnull(ri!xBaseNumberString), isnull(ri!base), ri!base > 36, ri!base < 2 ), null(), with( local!charset: left("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", ri!base), local!errorValue: -1, local!numCharacters: len(ri!xBaseNumberString), local!valueArray: a!forEach( items: reverse(enumerate(local!numCharacters)), expression: with( local!char: upper(ri!xBaseNumberString[fv!item + 1]), local!charPosition: find(local!char, local!charset), local!charValue: local!charPosition - 1, /* output: */ if( local!charPosition = 0, /* try to handle the case of the number string having invalid characters */ local!errorValue, local!charValue * (ri!base ^ (fv!index-1)) ) ) ), if( contains( local!valueArray, local!errorValue ), tointeger(null()), sum(local!valueArray) ) /* debug -- uncomment the following lines to see earlier calculated values */ /*&char(10) & "numchars: " & local!numCharacters*/ ) )