Re: "base" arithmetic in REXX
On Tue, 2 Aug 2011 17:25:38 -0500, Ward, Mike S wrote: >Ok how about something like this? > >/* REXX */ >input_number = 27 >XSTRING = D2C(input_number) >XTABLEI = '0102030405060708090A0B0C0D0E0F101112131415161718191A'x >XTABLEO = ABCDEFGHIJKLMNOPQRSTUVWXYZ >X = TRANSLATE(XSTRING,XTABLEO,XTABLEI) >say X "Base 26" refers to a number system in which each digit position has 26 possible values, just as in base 16 (hexadecimal) there are 16 possible valued in each digit position. The value of a digit at the rightmost position is multiplied by 26**0 (1). The next position is multiplied by 26**1 (26), the third position by 26**2 (676), etc. If the digit values are represented by the English letters A through Z, with A having values from 0 to 25, respectively, the counting sequence from decimal 1 through 26 would be B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, BA. -- Tom Marchant > >-Original Message- >From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On >Behalf Of John McKown >Sent: Monday, August 01, 2011 4:22 AM >To: IBM-MAIN@bama.ua.edu >Subject: "base" arithmetic in REXX > >anybody know an easy way to encode a base 10 number into base 26? >Basically, I want to make a decimal number into the English alphabet: >A-Z. I was hoping there was a simpler way than: > >i=input_number >output="" >alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" >do while i>0 > j=i//26 > output=substr(alphabet,j+1,1)||output > i=i%26 >end >output="A"||output >output=strip(output,"L","A") /* strip leading "A"s */ >if 0 = length(output) then output="A" -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
Ok how about something like this? /* REXX */ input_number = 27 XSTRING = D2C(input_number) XTABLEI = '0102030405060708090A0B0C0D0E0F101112131415161718191A'x XTABLEO = ABCDEFGHIJKLMNOPQRSTUVWXYZ X = TRANSLATE(XSTRING,XTABLEO,XTABLEI) say X -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of John McKown Sent: Monday, August 01, 2011 4:22 AM To: IBM-MAIN@bama.ua.edu Subject: "base" arithmetic in REXX anybody know an easy way to encode a base 10 number into base 26? Basically, I want to make a decimal number into the English alphabet: A-Z. I was hoping there was a simpler way than: i=input_number output="" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" do while i>0 j=i//26 output=substr(alphabet,j+1,1)||output i=i%26 end output="A"||output output=strip(output,"L","A") /* strip leading "A"s */ if 0 = length(output) then output="A" -- John McKown Maranatha! <>< -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html == This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
Forget that I did that. I see my error. -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of Ward, Mike S Sent: Tuesday, August 02, 2011 1:37 PM To: IBM-MAIN@bama.ua.edu Subject: Re: "base" arithmetic in REXX I'm not sure what you're trying to do, but how about this? /* REXX */ XSTRING = abcde119900116688fABCDEF XTABLEO = 1234567891234567892345678912345678912345678923456789 XTABLEI = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ X = TRANSLATE(XSTRING,XTABLEI,XTABLEO) say X RETURN -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of John McKown Sent: Monday, August 01, 2011 4:22 AM To: IBM-MAIN@bama.ua.edu Subject: "base" arithmetic in REXX anybody know an easy way to encode a base 10 number into base 26? Basically, I want to make a decimal number into the English alphabet: A-Z. I was hoping there was a simpler way than: i=input_number output="" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" do while i>0 j=i//26 output=substr(alphabet,j+1,1)||output i=i%26 end output="A"||output output=strip(output,"L","A") /* strip leading "A"s */ if 0 = length(output) then output="A" -- John McKown Maranatha! <>< -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html == This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html == This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
I'm not sure what you're trying to do, but how about this? /* REXX */ XSTRING = abcde119900116688fABCDEF XTABLEO = 1234567891234567892345678912345678912345678923456789 XTABLEI = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ X = TRANSLATE(XSTRING,XTABLEI,XTABLEO) say X RETURN -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of John McKown Sent: Monday, August 01, 2011 4:22 AM To: IBM-MAIN@bama.ua.edu Subject: "base" arithmetic in REXX anybody know an easy way to encode a base 10 number into base 26? Basically, I want to make a decimal number into the English alphabet: A-Z. I was hoping there was a simpler way than: i=input_number output="" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" do while i>0 j=i//26 output=substr(alphabet,j+1,1)||output i=i%26 end output="A"||output output=strip(output,"L","A") /* strip leading "A"s */ if 0 = length(output) then output="A" -- John McKown Maranatha! <>< -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html == This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
You made the best, this maybe the ermetic structure. I suppose that STRIP leading zeroes is unuseful in REXX /*Rexx*/ alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" say d2eng(input_number) Return d2eng: procedure expose alphabet i = arg(1) + 0 output="" do while i>0 output=substr(alphabet,i//26+1,1)||output i=i%26 end if 0 = length(output) then return "A" else return output If you need to run use it heavly(more than 30 times) you can also use stem instead substr i.e. /*Rexx*/ alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" j = 0 ; str = '' ; len = length(alphabet) do j = 1 to len str = str||j' alpha.'j' +1 ' end interpret "Parse Var alphabet "str say d2eng(1) Return d2eng: procedure expose alpha. len i = arg(1) + 0 output="" do while i>0 output=Value("alpha."i//len+1)||output /* or j = i//len+1 output=alpha.j||output */ i=i%len end if 0 = length(output) then return "A" else return output -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
Like this? - http://en.wikipedia.org/wiki/Base_36 (included is a Python examples, and links to other implementations. REXX left as an excercise for the reader :-) Kirk Wolf Dovetailed Technologies http://dovetail.com On Mon, Aug 1, 2011 at 9:35 AM, Norbert Friemel wrote: > On Mon, 1 Aug 2011 04:21:42 -0500, John McKown wrote: > > >anybody know an easy way to encode a base 10 number into base 26? > >Basically, I want to make a decimal number into the English alphabet: > >A-Z. I was hoping there was a simpler way than: > > > > Perhaps not "simpler": > > arg input_number . > if datatype(input_number,"W") & , > bpxwunix("typeset -i26 a &&let a="input_number "&&print > $a",,stdout.) = 0 & , > stdout.0 = 1 & , > left(stdout.1,3) = "26#" then > output = translate(substr(stdout.1,4), , > "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , > "0123456789abcdefghijklmnop") > else output = "A" > say output > > Have fun! > > Norbert Friemel > > -- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO > Search the archives at http://bama.ua.edu/archives/ibm-main.html > -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
I don't know rexx, but couldn't you just do an OC of X'F0" into the letter. A C1 would become F1 a C2 would become F2 and so on. -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of John McKown Sent: Monday, August 01, 2011 4:22 AM To: IBM-MAIN@bama.ua.edu Subject: "base" arithmetic in REXX anybody know an easy way to encode a base 10 number into base 26? Basically, I want to make a decimal number into the English alphabet: A-Z. I was hoping there was a simpler way than: i=input_number output="" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" do while i>0 j=i//26 output=substr(alphabet,j+1,1)||output i=i%26 end output="A"||output output=strip(output,"L","A") /* strip leading "A"s */ if 0 = length(output) then output="A" -- John McKown Maranatha! <>< -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html == This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
Re: "base" arithmetic in REXX
On Mon, 1 Aug 2011 04:21:42 -0500, John McKown wrote: >anybody know an easy way to encode a base 10 number into base 26? >Basically, I want to make a decimal number into the English alphabet: >A-Z. I was hoping there was a simpler way than: > Perhaps not "simpler": arg input_number . if datatype(input_number,"W") & , bpxwunix("typeset -i26 a &&let a="input_number "&&print $a",,stdout.) = 0 & , stdout.0 = 1 & , left(stdout.1,3) = "26#" then output = translate(substr(stdout.1,4), , "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , "0123456789abcdefghijklmnop") else output = "A" say output Have fun! Norbert Friemel -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html
"base" arithmetic in REXX
anybody know an easy way to encode a base 10 number into base 26? Basically, I want to make a decimal number into the English alphabet: A-Z. I was hoping there was a simpler way than: i=input_number output="" alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" do while i>0 j=i//26 output=substr(alphabet,j+1,1)||output i=i%26 end output="A"||output output=strip(output,"L","A") /* strip leading "A"s */ if 0 = length(output) then output="A" -- John McKown Maranatha! <>< -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO Search the archives at http://bama.ua.edu/archives/ibm-main.html