Base36

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William Stacey [MVP]

    Base36

    Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines? TIA

    --
    William Stacey, MVP


  • Roy Fine

    #2
    Re: Base36

    William,

    this is something that i did some time ago - actually for a different base,
    but it was easy enough to change to handle base32.

    you did not specify the symbol set for your number base - i will assume
    0,1,2,3... X,Y,Z. if yours is different, change the tokens string
    accordingly.

    for performance reasons, the weights of the digits are computed at compile
    time.

    note - there is absolutely no error checking, and it handles only positive
    values, and assumes that all character codes are upper case.

    regards
    roy fine


    namespace CONVERSION{
    // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
    public class BASE32{
    static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
    static long [] powers =
    {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *
    36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *
    36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *
    36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};

    public static string ToString(long lval){
    int maxStrLen = powers.Length;
    long curval = lval;
    char [] tb = new char[maxStrLen];
    int outpos = 0;
    for(int i=0; i<maxStrLen; i++){
    long pval = powers[maxStrLen - i - 1];
    int pos = (int)(curval / pval);
    tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
    curval = curval % pval;
    }
    if(outpos==0) tb[outpos++] = '0';
    return new string(tb,0,out pos).TrimStart( '0');
    }

    public static long ToLong(string t){
    long ival = 0;
    char [] tb = t.ToCharArray() ;
    for(int i=0; i<tb.Length; i++){
    ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
    }
    return ival;
    }
    }
    }

    "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
    news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?[/color]
    TIA[color=blue]
    >
    > --
    > William Stacey, MVP
    > http://mvp.support.microsoft.com
    >[/color]


    Comment

    • William Stacey [MVP]

      #3
      Re: Base36

      Hey thanks a lot Roy. Care to post the other base as well? Either way,
      thanks again!!

      --
      William Stacey, MVP


      "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
      news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...[color=blue]
      > William,
      >
      > this is something that i did some time ago - actually for a different[/color]
      base,[color=blue]
      > but it was easy enough to change to handle base32.
      >
      > you did not specify the symbol set for your number base - i will assume
      > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
      > accordingly.
      >
      > for performance reasons, the weights of the digits are computed at compile
      > time.
      >
      > note - there is absolutely no error checking, and it handles only positive
      > values, and assumes that all character codes are upper case.
      >
      > regards
      > roy fine
      >
      >
      > namespace CONVERSION{
      > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
      > public class BASE32{
      > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
      > static long [] powers =
      >[/color]
      {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue]
      >[/color]
      36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue]
      >[/color]
      36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue]
      > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
      >
      > public static string ToString(long lval){
      > int maxStrLen = powers.Length;
      > long curval = lval;
      > char [] tb = new char[maxStrLen];
      > int outpos = 0;
      > for(int i=0; i<maxStrLen; i++){
      > long pval = powers[maxStrLen - i - 1];
      > int pos = (int)(curval / pval);
      > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
      > curval = curval % pval;
      > }
      > if(outpos==0) tb[outpos++] = '0';
      > return new string(tb,0,out pos).TrimStart( '0');
      > }
      >
      > public static long ToLong(string t){
      > long ival = 0;
      > char [] tb = t.ToCharArray() ;
      > for(int i=0; i<tb.Length; i++){
      > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
      > }
      > return ival;
      > }
      > }
      > }
      >
      > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
      > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..[color=green]
      > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?[/color]
      > TIA[color=green]
      > >
      > > --
      > > William Stacey, MVP
      > > http://mvp.support.microsoft.com
      > >[/color]
      >
      >[/color]

      Comment

      • Justin Rogers

        #4
        Re: Base36

        A generic base conversion can be applied by taking an alphabet:

        private void char[] alphabet = new char[] {'0','1','2','3 ','4'}; // Base 5

        private string IntegerToBase(i nt foo, char[] alphabet) {
        int base = alphabet.Length ;
        string baseStr = "";
        do {
        baseStr = alphabet[foo%base] + baseStr;
        foo /= base;
        } while(foo > 0);

        return baseStr
        }

        Given any alphabet, you can now go one way from integers to the base.
        The reverse is more complicated, but only because certain assumptions
        have to be made (converting from a well known type with specific rules
        such as an integer is always easier than converting from an arbitrary type
        where rules aren't self-imposed within a string).

        I'm sure you also need the reverse. I already have numerous parsing
        and conversion routines located in the blog space, so I'll try and elevate
        this to a blog posting, and then back it with an article that contains links
        and short details to all of my parsing routines to make them more
        accessible.

        --
        Justin Rogers
        DigiTec Web Consultants, LLC.
        Blog: http://weblogs.asp.net/justin_rogers

        "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
        news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Hey thanks a lot Roy. Care to post the other base as well? Either way,
        > thanks again!!
        >
        > --
        > William Stacey, MVP
        > http://mvp.support.microsoft.com
        >
        > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
        > news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...[color=green]
        >> William,
        >>
        >> this is something that i did some time ago - actually for a different[/color]
        > base,[color=green]
        >> but it was easy enough to change to handle base32.
        >>
        >> you did not specify the symbol set for your number base - i will assume
        >> 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
        >> accordingly.
        >>
        >> for performance reasons, the weights of the digits are computed at compile
        >> time.
        >>
        >> note - there is absolutely no error checking, and it handles only positive
        >> values, and assumes that all character codes are upper case.
        >>
        >> regards
        >> roy fine
        >>
        >>
        >> namespace CONVERSION{
        >> // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
        >> public class BASE32{
        >> static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
        >> static long [] powers =
        >>[/color]
        > {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=green]
        >>[/color]
        > 36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green]
        >>[/color]
        > 36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green]
        >> 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
        >>
        >> public static string ToString(long lval){
        >> int maxStrLen = powers.Length;
        >> long curval = lval;
        >> char [] tb = new char[maxStrLen];
        >> int outpos = 0;
        >> for(int i=0; i<maxStrLen; i++){
        >> long pval = powers[maxStrLen - i - 1];
        >> int pos = (int)(curval / pval);
        >> tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
        >> curval = curval % pval;
        >> }
        >> if(outpos==0) tb[outpos++] = '0';
        >> return new string(tb,0,out pos).TrimStart( '0');
        >> }
        >>
        >> public static long ToLong(string t){
        >> long ival = 0;
        >> char [] tb = t.ToCharArray() ;
        >> for(int i=0; i<tb.Length; i++){
        >> ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
        >> }
        >> return ival;
        >> }
        >> }
        >> }
        >>
        >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
        >> news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
        >> > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?[/color]
        >> TIA[color=darkred]
        >> >
        >> > --
        >> > William Stacey, MVP
        >> > http://mvp.support.microsoft.com
        >> >[/color]
        >>
        >>[/color]
        >[/color]


        Comment

        • Roy Fine

          #5
          Re: Base36

          William

          The other base was base 26 and used *just* the uppercase alphabetic
          characters (A..Z). The only change would be to specify the token set of the
          number set and the weights of each position. For the Base26 case, it was
          this:

          /* *************** ** */
          public class BASE32{
          static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
          static long [] powers =
          {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *
          26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
          26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
          26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
          ....
          ....
          }
          /* *************** ** */

          conversion is each direction is based on the tokens and powers arrays. the
          first entry in the tokens aray always corresponds to the empty or zero
          value, etc.

          happy to help
          roy


          "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
          news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hey thanks a lot Roy. Care to post the other base as well? Either way,
          > thanks again!!
          >
          > --
          > William Stacey, MVP
          > http://mvp.support.microsoft.com
          >
          > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
          > news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...[color=green]
          > > William,
          > >
          > > this is something that i did some time ago - actually for a different[/color]
          > base,[color=green]
          > > but it was easy enough to change to handle base32.
          > >
          > > you did not specify the symbol set for your number base - i will assume
          > > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
          > > accordingly.
          > >
          > > for performance reasons, the weights of the digits are computed at[/color][/color]
          compile[color=blue][color=green]
          > > time.
          > >
          > > note - there is absolutely no error checking, and it handles only[/color][/color]
          positive[color=blue][color=green]
          > > values, and assumes that all character codes are upper case.
          > >
          > > regards
          > > roy fine
          > >
          > >
          > > namespace CONVERSION{
          > > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
          > > public class BASE32{
          > > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
          > > static long [] powers =
          > >[/color]
          >[/color]
          {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green]
          > >[/color]
          >[/color]
          36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green]
          > >[/color]
          >[/color]
          36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green]
          > > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
          > >
          > > public static string ToString(long lval){
          > > int maxStrLen = powers.Length;
          > > long curval = lval;
          > > char [] tb = new char[maxStrLen];
          > > int outpos = 0;
          > > for(int i=0; i<maxStrLen; i++){
          > > long pval = powers[maxStrLen - i - 1];
          > > int pos = (int)(curval / pval);
          > > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
          > > curval = curval % pval;
          > > }
          > > if(outpos==0) tb[outpos++] = '0';
          > > return new string(tb,0,out pos).TrimStart( '0');
          > > }
          > >
          > > public static long ToLong(string t){
          > > long ival = 0;
          > > char [] tb = t.ToCharArray() ;
          > > for(int i=0; i<tb.Length; i++){
          > > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
          > > }
          > > return ival;
          > > }
          > > }
          > > }
          > >
          > > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
          > > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
          > > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion[/color][/color][/color]
          routines?[color=blue][color=green]
          > > TIA[color=darkred]
          > > >
          > > > --
          > > > William Stacey, MVP
          > > > http://mvp.support.microsoft.com
          > > >[/color]
          > >
          > >[/color]
          >[/color]


          Comment

          • Justin Rogers

            #6
            Re: Base36

            Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2 through
            base36.

            The notes are extensive as to the direction the library may or may not go
            depending on what
            problems people are trying to solve. What I've realized is that there are a
            number of additional
            and interesting problems associated with alphabet encoding, such as permuations,
            cyclic
            rotations, error correction, and the like that may be interesting to build into
            the libraries. An
            example of an error correction alphabet would be the base32 encoding which
            removes
            characters that may be confused for other characters when read by a human.


            --
            Justin Rogers
            DigiTec Web Consultants, LLC.
            Blog: http://weblogs.asp.net/justin_rogers

            "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
            news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=blue]
            > William
            >
            > The other base was base 26 and used *just* the uppercase alphabetic
            > characters (A..Z). The only change would be to specify the token set of the
            > number set and the weights of each position. For the Base26 case, it was
            > this:
            >
            > /* *************** ** */
            > public class BASE32{
            > static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
            > static long [] powers =
            > {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *
            > 26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
            > 26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
            > 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
            > ...
            > ...
            > }
            > /* *************** ** */
            >
            > conversion is each direction is based on the tokens and powers arrays. the
            > first entry in the tokens aray always corresponds to the empty or zero
            > value, etc.
            >
            > happy to help
            > roy
            >
            >
            > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
            > news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=green]
            >> Hey thanks a lot Roy. Care to post the other base as well? Either way,
            >> thanks again!!
            >>
            >> --
            >> William Stacey, MVP
            >> http://mvp.support.microsoft.com
            >>
            >> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
            >> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...[color=darkred]
            >> > William,
            >> >
            >> > this is something that i did some time ago - actually for a different[/color]
            >> base,[color=darkred]
            >> > but it was easy enough to change to handle base32.
            >> >
            >> > you did not specify the symbol set for your number base - i will assume
            >> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
            >> > accordingly.
            >> >
            >> > for performance reasons, the weights of the digits are computed at[/color][/color]
            > compile[color=green][color=darkred]
            >> > time.
            >> >
            >> > note - there is absolutely no error checking, and it handles only[/color][/color]
            > positive[color=green][color=darkred]
            >> > values, and assumes that all character codes are upper case.
            >> >
            >> > regards
            >> > roy fine
            >> >
            >> >
            >> > namespace CONVERSION{
            >> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
            >> > public class BASE32{
            >> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
            >> > static long [] powers =
            >> >[/color]
            >>[/color]
            > {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=green][color=darkred]
            >> >[/color]
            >>[/color]
            > 36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
            >> >[/color]
            >>[/color]
            > 36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
            >> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
            >> >
            >> > public static string ToString(long lval){
            >> > int maxStrLen = powers.Length;
            >> > long curval = lval;
            >> > char [] tb = new char[maxStrLen];
            >> > int outpos = 0;
            >> > for(int i=0; i<maxStrLen; i++){
            >> > long pval = powers[maxStrLen - i - 1];
            >> > int pos = (int)(curval / pval);
            >> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
            >> > curval = curval % pval;
            >> > }
            >> > if(outpos==0) tb[outpos++] = '0';
            >> > return new string(tb,0,out pos).TrimStart( '0');
            >> > }
            >> >
            >> > public static long ToLong(string t){
            >> > long ival = 0;
            >> > char [] tb = t.ToCharArray() ;
            >> > for(int i=0; i<tb.Length; i++){
            >> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
            >> > }
            >> > return ival;
            >> > }
            >> > }
            >> > }
            >> >
            >> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
            >> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
            >> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion[/color][/color]
            > routines?[color=green][color=darkred]
            >> > TIA
            >> > >
            >> > > --
            >> > > William Stacey, MVP
            >> > > http://mvp.support.microsoft.com
            >> > >
            >> >
            >> >[/color]
            >>[/color]
            >
            >[/color]


            Comment

            • Justin Rogers

              #7
              Re: Base36

              Apparentyly it whacked the link...




              --
              Justin Rogers
              DigiTec Web Consultants, LLC.
              Blog: http://weblogs.asp.net/justin_rogers


              "Justin Rogers" <Justin@games4d otnet.com> wrote in message
              news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...[color=blue]
              > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2 through
              > base36.
              >
              > The notes are extensive as to the direction the library may or may not go
              > depending on what
              > problems people are trying to solve. What I've realized is that there are a
              > number of additional
              > and interesting problems associated with alphabet encoding, such as
              > permuations, cyclic
              > rotations, error correction, and the like that may be interesting to build
              > into the libraries. An
              > example of an error correction alphabet would be the base32 encoding which
              > removes
              > characters that may be confused for other characters when read by a human.
              >
              >
              > --
              > Justin Rogers
              > DigiTec Web Consultants, LLC.
              > Blog: http://weblogs.asp.net/justin_rogers
              >
              > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
              > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=green]
              >> William
              >>
              >> The other base was base 26 and used *just* the uppercase alphabetic
              >> characters (A..Z). The only change would be to specify the token set of the
              >> number set and the weights of each position. For the Base26 case, it was
              >> this:
              >>
              >> /* *************** ** */
              >> public class BASE32{
              >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
              >> static long [] powers =
              >> {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *
              >> 26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
              >> 26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *
              >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
              >> ...
              >> ...
              >> }
              >> /* *************** ** */
              >>
              >> conversion is each direction is based on the tokens and powers arrays. the
              >> first entry in the tokens aray always corresponds to the empty or zero
              >> value, etc.
              >>
              >> happy to help
              >> roy
              >>
              >>
              >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
              >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=darkred]
              >>> Hey thanks a lot Roy. Care to post the other base as well? Either way,
              >>> thanks again!!
              >>>
              >>> --
              >>> William Stacey, MVP
              >>> http://mvp.support.microsoft.com
              >>>
              >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
              >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
              >>> > William,
              >>> >
              >>> > this is something that i did some time ago - actually for a different
              >>> base,
              >>> > but it was easy enough to change to handle base32.
              >>> >
              >>> > you did not specify the symbol set for your number base - i will assume
              >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
              >>> > accordingly.
              >>> >
              >>> > for performance reasons, the weights of the digits are computed at[/color]
              >> compile[color=darkred]
              >>> > time.
              >>> >
              >>> > note - there is absolutely no error checking, and it handles only[/color]
              >> positive[color=darkred]
              >>> > values, and assumes that all character codes are upper case.
              >>> >
              >>> > regards
              >>> > roy fine
              >>> >
              >>> >
              >>> > namespace CONVERSION{
              >>> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
              >>> > public class BASE32{
              >>> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
              >>> > static long [] powers =
              >>> >
              >>>[/color]
              >> {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=darkred]
              >>> >
              >>>[/color]
              >> 36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=darkred]
              >>> >
              >>>[/color]
              >> 36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=darkred]
              >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
              >>> >
              >>> > public static string ToString(long lval){
              >>> > int maxStrLen = powers.Length;
              >>> > long curval = lval;
              >>> > char [] tb = new char[maxStrLen];
              >>> > int outpos = 0;
              >>> > for(int i=0; i<maxStrLen; i++){
              >>> > long pval = powers[maxStrLen - i - 1];
              >>> > int pos = (int)(curval / pval);
              >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
              >>> > curval = curval % pval;
              >>> > }
              >>> > if(outpos==0) tb[outpos++] = '0';
              >>> > return new string(tb,0,out pos).TrimStart( '0');
              >>> > }
              >>> >
              >>> > public static long ToLong(string t){
              >>> > long ival = 0;
              >>> > char [] tb = t.ToCharArray() ;
              >>> > for(int i=0; i<tb.Length; i++){
              >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
              >>> > }
              >>> > return ival;
              >>> > }
              >>> > }
              >>> > }
              >>> >
              >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
              >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
              >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion[/color]
              >> routines?[color=darkred]
              >>> > TIA
              >>> > >
              >>> > > --
              >>> > > William Stacey, MVP
              >>> > > http://mvp.support.microsoft.com
              >>> > >
              >>> >
              >>> >
              >>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • Roy Fine

                #8
                Re: Base36


                "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                news:uPrrmBSxEH A.1264@TK2MSFTN GP12.phx.gbl...[color=blue]
                > Apparentyly it whacked the link...
                >
                > http://weblogs.asp.net/justin_rogers...es/253641.aspx
                >
                >[/color]

                nice - but the code i posted works, begs for a bit of optimization, but
                comes with *no* strings attached.

                rlf


                [color=blue]
                > --
                > Justin Rogers
                > DigiTec Web Consultants, LLC.
                > Blog: http://weblogs.asp.net/justin_rogers
                >
                >
                > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                > news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...[color=green]
                > > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2[/color][/color]
                through[color=blue][color=green]
                > > base36.
                > >
                > > The notes are extensive as to the direction the library may or may not[/color][/color]
                go[color=blue][color=green]
                > > depending on what
                > > problems people are trying to solve. What I've realized is that there[/color][/color]
                are a[color=blue][color=green]
                > > number of additional
                > > and interesting problems associated with alphabet encoding, such as
                > > permuations, cyclic
                > > rotations, error correction, and the like that may be interesting to[/color][/color]
                build[color=blue][color=green]
                > > into the libraries. An
                > > example of an error correction alphabet would be the base32 encoding[/color][/color]
                which[color=blue][color=green]
                > > removes
                > > characters that may be confused for other characters when read by a[/color][/color]
                human.[color=blue][color=green]
                > >
                > >
                > > --
                > > Justin Rogers
                > > DigiTec Web Consultants, LLC.
                > > Blog: http://weblogs.asp.net/justin_rogers
                > >
                > > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                > > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=darkred]
                > >> William
                > >>
                > >> The other base was base 26 and used *just* the uppercase alphabetic
                > >> characters (A..Z). The only change would be to specify the token set[/color][/color][/color]
                of the[color=blue][color=green][color=darkred]
                > >> number set and the weights of each position. For the Base26 case, it[/color][/color][/color]
                was[color=blue][color=green][color=darkred]
                > >> this:
                > >>
                > >> /* *************** ** */
                > >> public class BASE32{
                > >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                > >> static long [] powers =
                > >>[/color][/color][/color]
                {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=blue][color=green][color=darkred]
                > >>[/color][/color][/color]
                26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                > >>[/color][/color][/color]
                26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                > >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                > >> ...
                > >> ...
                > >> }
                > >> /* *************** ** */
                > >>
                > >> conversion is each direction is based on the tokens and powers arrays.[/color][/color][/color]
                the[color=blue][color=green][color=darkred]
                > >> first entry in the tokens aray always corresponds to the empty or zero
                > >> value, etc.
                > >>
                > >> happy to help
                > >> roy
                > >>
                > >>
                > >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                > >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                > >>> Hey thanks a lot Roy. Care to post the other base as well? Either[/color][/color][/color]
                way,[color=blue][color=green][color=darkred]
                > >>> thanks again!!
                > >>>
                > >>> --
                > >>> William Stacey, MVP
                > >>> http://mvp.support.microsoft.com
                > >>>
                > >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                > >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                > >>> > William,
                > >>> >
                > >>> > this is something that i did some time ago - actually for a[/color][/color][/color]
                different[color=blue][color=green][color=darkred]
                > >>> base,
                > >>> > but it was easy enough to change to handle base32.
                > >>> >
                > >>> > you did not specify the symbol set for your number base - i will[/color][/color][/color]
                assume[color=blue][color=green][color=darkred]
                > >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
                > >>> > accordingly.
                > >>> >
                > >>> > for performance reasons, the weights of the digits are computed at
                > >> compile
                > >>> > time.
                > >>> >
                > >>> > note - there is absolutely no error checking, and it handles only
                > >> positive
                > >>> > values, and assumes that all character codes are upper case.
                > >>> >
                > >>> > regards
                > >>> > roy fine
                > >>> >
                > >>> >
                > >>> > namespace CONVERSION{
                > >>> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
                > >>> > public class BASE32{
                > >>> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                > >>> > static long [] powers =
                > >>> >
                > >>>
                > >>[/color][/color][/color]
                {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green][color=darkred]
                > >>> >
                > >>>
                > >>[/color][/color][/color]
                36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                > >>> >
                > >>>
                > >>[/color][/color][/color]
                36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                > >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                > >>> >
                > >>> > public static string ToString(long lval){
                > >>> > int maxStrLen = powers.Length;
                > >>> > long curval = lval;
                > >>> > char [] tb = new char[maxStrLen];
                > >>> > int outpos = 0;
                > >>> > for(int i=0; i<maxStrLen; i++){
                > >>> > long pval = powers[maxStrLen - i - 1];
                > >>> > int pos = (int)(curval / pval);
                > >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                > >>> > curval = curval % pval;
                > >>> > }
                > >>> > if(outpos==0) tb[outpos++] = '0';
                > >>> > return new string(tb,0,out pos).TrimStart( '0');
                > >>> > }
                > >>> >
                > >>> > public static long ToLong(string t){
                > >>> > long ival = 0;
                > >>> > char [] tb = t.ToCharArray() ;
                > >>> > for(int i=0; i<tb.Length; i++){
                > >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                > >>> > }
                > >>> > return ival;
                > >>> > }
                > >>> > }
                > >>> > }
                > >>> >
                > >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                > >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                > >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
                > >> routines?
                > >>> > TIA
                > >>> > >
                > >>> > > --
                > >>> > > William Stacey, MVP
                > >>> > > http://mvp.support.microsoft.com
                > >>> > >
                > >>> >
                > >>> >
                > >>>
                > >>
                > >>[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Justin Rogers

                  #9
                  Re: Base36

                  Ah, I wasn't aware alerting the author about changes to the code
                  that you've made is a string being attached. The licensing agreement
                  at the top is primarily a joke for all those that read it. It even requires
                  that you laugh... I put it there to reduce my own liability and to point
                  out that the software isn't supported. Take it for what you will.


                  --
                  Justin Rogers
                  DigiTec Web Consultants, LLC.
                  Blog: http://weblogs.asp.net/justin_rogers

                  "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                  news:%23sZN8bSx EHA.2196@TK2MSF TNGP14.phx.gbl. ..[color=blue]
                  >
                  > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                  > news:uPrrmBSxEH A.1264@TK2MSFTN GP12.phx.gbl...[color=green]
                  >> Apparentyly it whacked the link...
                  >>
                  >> http://weblogs.asp.net/justin_rogers...es/253641.aspx
                  >>
                  >>[/color]
                  >
                  > nice - but the code i posted works, begs for a bit of optimization, but
                  > comes with *no* strings attached.
                  >
                  > rlf
                  >
                  >
                  >[color=green]
                  >> --
                  >> Justin Rogers
                  >> DigiTec Web Consultants, LLC.
                  >> Blog: http://weblogs.asp.net/justin_rogers
                  >>
                  >>
                  >> "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                  >> news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...[color=darkred]
                  >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2[/color][/color]
                  > through[color=green][color=darkred]
                  >> > base36.
                  >> >
                  >> > The notes are extensive as to the direction the library may or may not[/color][/color]
                  > go[color=green][color=darkred]
                  >> > depending on what
                  >> > problems people are trying to solve. What I've realized is that there[/color][/color]
                  > are a[color=green][color=darkred]
                  >> > number of additional
                  >> > and interesting problems associated with alphabet encoding, such as
                  >> > permuations, cyclic
                  >> > rotations, error correction, and the like that may be interesting to[/color][/color]
                  > build[color=green][color=darkred]
                  >> > into the libraries. An
                  >> > example of an error correction alphabet would be the base32 encoding[/color][/color]
                  > which[color=green][color=darkred]
                  >> > removes
                  >> > characters that may be confused for other characters when read by a[/color][/color]
                  > human.[color=green][color=darkred]
                  >> >
                  >> >
                  >> > --
                  >> > Justin Rogers
                  >> > DigiTec Web Consultants, LLC.
                  >> > Blog: http://weblogs.asp.net/justin_rogers
                  >> >
                  >> > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                  >> > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...
                  >> >> William
                  >> >>
                  >> >> The other base was base 26 and used *just* the uppercase alphabetic
                  >> >> characters (A..Z). The only change would be to specify the token set[/color][/color]
                  > of the[color=green][color=darkred]
                  >> >> number set and the weights of each position. For the Base26 case, it[/color][/color]
                  > was[color=green][color=darkred]
                  >> >> this:
                  >> >>
                  >> >> /* *************** ** */
                  >> >> public class BASE32{
                  >> >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                  >> >> static long [] powers =
                  >> >>[/color][/color]
                  > {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=green][color=darkred]
                  >> >>[/color][/color]
                  > 26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=green][color=darkred]
                  >> >>[/color][/color]
                  > 26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=green][color=darkred]
                  >> >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                  >> >> ...
                  >> >> ...
                  >> >> }
                  >> >> /* *************** ** */
                  >> >>
                  >> >> conversion is each direction is based on the tokens and powers arrays.[/color][/color]
                  > the[color=green][color=darkred]
                  >> >> first entry in the tokens aray always corresponds to the empty or zero
                  >> >> value, etc.
                  >> >>
                  >> >> happy to help
                  >> >> roy
                  >> >>
                  >> >>
                  >> >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                  >> >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                  >> >>> Hey thanks a lot Roy. Care to post the other base as well? Either[/color][/color]
                  > way,[color=green][color=darkred]
                  >> >>> thanks again!!
                  >> >>>
                  >> >>> --
                  >> >>> William Stacey, MVP
                  >> >>> http://mvp.support.microsoft.com
                  >> >>>
                  >> >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                  >> >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                  >> >>> > William,
                  >> >>> >
                  >> >>> > this is something that i did some time ago - actually for a[/color][/color]
                  > different[color=green][color=darkred]
                  >> >>> base,
                  >> >>> > but it was easy enough to change to handle base32.
                  >> >>> >
                  >> >>> > you did not specify the symbol set for your number base - i will[/color][/color]
                  > assume[color=green][color=darkred]
                  >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
                  >> >>> > accordingly.
                  >> >>> >
                  >> >>> > for performance reasons, the weights of the digits are computed at
                  >> >> compile
                  >> >>> > time.
                  >> >>> >
                  >> >>> > note - there is absolutely no error checking, and it handles only
                  >> >> positive
                  >> >>> > values, and assumes that all character codes are upper case.
                  >> >>> >
                  >> >>> > regards
                  >> >>> > roy fine
                  >> >>> >
                  >> >>> >
                  >> >>> > namespace CONVERSION{
                  >> >>> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
                  >> >>> > public class BASE32{
                  >> >>> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                  >> >>> > static long [] powers =
                  >> >>> >
                  >> >>>
                  >> >>[/color][/color]
                  > {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=green][color=darkred]
                  >> >>> >
                  >> >>>
                  >> >>[/color][/color]
                  > 36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
                  >> >>> >
                  >> >>>
                  >> >>[/color][/color]
                  > 36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
                  >> >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                  >> >>> >
                  >> >>> > public static string ToString(long lval){
                  >> >>> > int maxStrLen = powers.Length;
                  >> >>> > long curval = lval;
                  >> >>> > char [] tb = new char[maxStrLen];
                  >> >>> > int outpos = 0;
                  >> >>> > for(int i=0; i<maxStrLen; i++){
                  >> >>> > long pval = powers[maxStrLen - i - 1];
                  >> >>> > int pos = (int)(curval / pval);
                  >> >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                  >> >>> > curval = curval % pval;
                  >> >>> > }
                  >> >>> > if(outpos==0) tb[outpos++] = '0';
                  >> >>> > return new string(tb,0,out pos).TrimStart( '0');
                  >> >>> > }
                  >> >>> >
                  >> >>> > public static long ToLong(string t){
                  >> >>> > long ival = 0;
                  >> >>> > char [] tb = t.ToCharArray() ;
                  >> >>> > for(int i=0; i<tb.Length; i++){
                  >> >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                  >> >>> > }
                  >> >>> > return ival;
                  >> >>> > }
                  >> >>> > }
                  >> >>> > }
                  >> >>> >
                  >> >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                  >> >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                  >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
                  >> >> routines?
                  >> >>> > TIA
                  >> >>> > >
                  >> >>> > > --
                  >> >>> > > William Stacey, MVP
                  >> >>> > > http://mvp.support.microsoft.com
                  >> >>> > >
                  >> >>> >
                  >> >>> >
                  >> >>>
                  >> >>
                  >> >>
                  >> >
                  >> >[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Roy Fine

                    #10
                    Re: Base36


                    "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                    news:eTwFu0SxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=blue]
                    > Ah, I wasn't aware alerting the author about changes to the code
                    > that you've made is a string being attached. The licensing agreement
                    > at the top is primarily a joke for all those that read it. It even[/color]
                    requires[color=blue]
                    > that you laugh... I put it there to reduce my own liability and to point
                    > out that the software isn't supported. Take it for what you will.
                    >[/color]

                    what the "recommende d interpretation" of :

                    <quote>
                    The use of this software is for test and performance purposes only.

                    <\quote>

                    and

                    <quote>
                    In all seriousness,
                    excluding the laughter, laughter in itself does not void this license
                    agreement, nor compromise it's ability to legally bind you.
                    <\quote>
                    [color=blue]
                    >
                    > --
                    > Justin Rogers
                    > DigiTec Web Consultants, LLC.
                    > Blog: http://weblogs.asp.net/justin_rogers
                    >
                    > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                    > news:%23sZN8bSx EHA.2196@TK2MSF TNGP14.phx.gbl. ..[color=green]
                    > >
                    > > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                    > > news:uPrrmBSxEH A.1264@TK2MSFTN GP12.phx.gbl...[color=darkred]
                    > >> Apparentyly it whacked the link...
                    > >>
                    > >> http://weblogs.asp.net/justin_rogers...es/253641.aspx
                    > >>
                    > >>[/color]
                    > >
                    > > nice - but the code i posted works, begs for a bit of optimization, but
                    > > comes with *no* strings attached.
                    > >
                    > > rlf
                    > >
                    > >
                    > >[color=darkred]
                    > >> --
                    > >> Justin Rogers
                    > >> DigiTec Web Consultants, LLC.
                    > >> Blog: http://weblogs.asp.net/justin_rogers
                    > >>
                    > >>
                    > >> "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                    > >> news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...
                    > >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2[/color]
                    > > through[color=darkred]
                    > >> > base36.
                    > >> >
                    > >> > The notes are extensive as to the direction the library may or may[/color][/color][/color]
                    not[color=blue][color=green]
                    > > go[color=darkred]
                    > >> > depending on what
                    > >> > problems people are trying to solve. What I've realized is that there[/color]
                    > > are a[color=darkred]
                    > >> > number of additional
                    > >> > and interesting problems associated with alphabet encoding, such as
                    > >> > permuations, cyclic
                    > >> > rotations, error correction, and the like that may be interesting to[/color]
                    > > build[color=darkred]
                    > >> > into the libraries. An
                    > >> > example of an error correction alphabet would be the base32 encoding[/color]
                    > > which[color=darkred]
                    > >> > removes
                    > >> > characters that may be confused for other characters when read by a[/color]
                    > > human.[color=darkred]
                    > >> >
                    > >> >
                    > >> > --
                    > >> > Justin Rogers
                    > >> > DigiTec Web Consultants, LLC.
                    > >> > Blog: http://weblogs.asp.net/justin_rogers
                    > >> >
                    > >> > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                    > >> > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...
                    > >> >> William
                    > >> >>
                    > >> >> The other base was base 26 and used *just* the uppercase alphabetic
                    > >> >> characters (A..Z). The only change would be to specify the token[/color][/color][/color]
                    set[color=blue][color=green]
                    > > of the[color=darkred]
                    > >> >> number set and the weights of each position. For the Base26 case,[/color][/color][/color]
                    it[color=blue][color=green]
                    > > was[color=darkred]
                    > >> >> this:
                    > >> >>
                    > >> >> /* *************** ** */
                    > >> >> public class BASE32{
                    > >> >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                    > >> >> static long [] powers =
                    > >> >>[/color]
                    > >[/color][/color]
                    {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=blue][color=green][color=darkred]
                    > >> >>[/color]
                    > >[/color][/color]
                    26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                    > >> >>[/color]
                    > >[/color][/color]
                    26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                    > >> >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                    > >> >> ...
                    > >> >> ...
                    > >> >> }
                    > >> >> /* *************** ** */
                    > >> >>
                    > >> >> conversion is each direction is based on the tokens and powers[/color][/color][/color]
                    arrays.[color=blue][color=green]
                    > > the[color=darkred]
                    > >> >> first entry in the tokens aray always corresponds to the empty or[/color][/color][/color]
                    zero[color=blue][color=green][color=darkred]
                    > >> >> value, etc.
                    > >> >>
                    > >> >> happy to help
                    > >> >> roy
                    > >> >>
                    > >> >>
                    > >> >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                    > >> >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                    > >> >>> Hey thanks a lot Roy. Care to post the other base as well? Either[/color]
                    > > way,[color=darkred]
                    > >> >>> thanks again!!
                    > >> >>>
                    > >> >>> --
                    > >> >>> William Stacey, MVP
                    > >> >>> http://mvp.support.microsoft.com
                    > >> >>>
                    > >> >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                    > >> >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                    > >> >>> > William,
                    > >> >>> >
                    > >> >>> > this is something that i did some time ago - actually for a[/color]
                    > > different[color=darkred]
                    > >> >>> base,
                    > >> >>> > but it was easy enough to change to handle base32.
                    > >> >>> >
                    > >> >>> > you did not specify the symbol set for your number base - i will[/color]
                    > > assume[color=darkred]
                    > >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens[/color][/color][/color]
                    string[color=blue][color=green][color=darkred]
                    > >> >>> > accordingly.
                    > >> >>> >
                    > >> >>> > for performance reasons, the weights of the digits are computed[/color][/color][/color]
                    at[color=blue][color=green][color=darkred]
                    > >> >> compile
                    > >> >>> > time.
                    > >> >>> >
                    > >> >>> > note - there is absolutely no error checking, and it handles only
                    > >> >> positive
                    > >> >>> > values, and assumes that all character codes are upper case.
                    > >> >>> >
                    > >> >>> > regards
                    > >> >>> > roy fine
                    > >> >>> >
                    > >> >>> >
                    > >> >>> > namespace CONVERSION{
                    > >> >>> > // handles positive only values up to 4,738,381,338,3 21,616,896 -[/color][/color][/color]
                    1;[color=blue][color=green][color=darkred]
                    > >> >>> > public class BASE32{
                    > >> >>> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                    > >> >>> > static long [] powers =
                    > >> >>> >
                    > >> >>>
                    > >> >>[/color]
                    > >[/color][/color]
                    {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green][color=darkred]
                    > >> >>> >
                    > >> >>>
                    > >> >>[/color]
                    > >[/color][/color]
                    36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                    > >> >>> >
                    > >> >>>
                    > >> >>[/color]
                    > >[/color][/color]
                    36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                    > >> >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                    > >> >>> >
                    > >> >>> > public static string ToString(long lval){
                    > >> >>> > int maxStrLen = powers.Length;
                    > >> >>> > long curval = lval;
                    > >> >>> > char [] tb = new char[maxStrLen];
                    > >> >>> > int outpos = 0;
                    > >> >>> > for(int i=0; i<maxStrLen; i++){
                    > >> >>> > long pval = powers[maxStrLen - i - 1];
                    > >> >>> > int pos = (int)(curval / pval);
                    > >> >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                    > >> >>> > curval = curval % pval;
                    > >> >>> > }
                    > >> >>> > if(outpos==0) tb[outpos++] = '0';
                    > >> >>> > return new string(tb,0,out pos).TrimStart( '0');
                    > >> >>> > }
                    > >> >>> >
                    > >> >>> > public static long ToLong(string t){
                    > >> >>> > long ival = 0;
                    > >> >>> > char [] tb = t.ToCharArray() ;
                    > >> >>> > for(int i=0; i<tb.Length; i++){
                    > >> >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                    > >> >>> > }
                    > >> >>> > return ival;
                    > >> >>> > }
                    > >> >>> > }
                    > >> >>> > }
                    > >> >>> >
                    > >> >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                    > >> >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                    > >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
                    > >> >> routines?
                    > >> >>> > TIA
                    > >> >>> > >
                    > >> >>> > > --
                    > >> >>> > > William Stacey, MVP
                    > >> >>> > > http://mvp.support.microsoft.com
                    > >> >>> > >
                    > >> >>> >
                    > >> >>> >
                    > >> >>>
                    > >> >>
                    > >> >>
                    > >> >
                    > >> >
                    > >>
                    > >>[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • William Stacey [MVP]

                      #11
                      Re: Base36

                      Thanks Roy. Could you expand the range by also including lower case a-z in
                      addition to uppercase A-Z?
                      If so, could you spoon feed me again with the updated logic if possible.
                      What I am looking to do is:
                      1) 5 base chars (0..9, a...z, A..Z) for count - max range up to
                      long.MaxRange if possible. Right now max range of ZZZZZ is 60,466,175.
                      2) Take a hash of count + some secret string(s) using PasswordDeriveB ytes
                      and convert as many bytes as possible to an alpha base encoding for a max of
                      "HHHH-HHHH-HHHC-CCCC" (five Count positions and 11 Hash positions) to get a
                      Product key (e.g. MSs). I should be able to recalc the hash at the client
                      using stripped out count and the shared secret to verify the calculated hash
                      matches the hash in the Product Key supplied. May need to break the hash
                      bytes into two longs (16 bytes) and maybe clear high order byte before the
                      conversion to long so I can pass each long to the BaseXX converter to get
                      the string. Right now I can do 7 bytes and be sure to stay in
                      473838133832161 6895 range.

                      I realize the secret is vulnerable, but think I can make it good enouph for
                      my needs as just an activation code. Anyway, hope above makes some sense.
                      Basically looking to encode bigger ranges (max longs or max ulongs, or
                      doubles if possible) with as few chars as possible in the valid set. Many
                      thanks again. Cheers.

                      --
                      William Stacey, MVP


                      "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                      news:u79ypMTxEH A.1396@tk2msftn gp13.phx.gbl...[color=blue]
                      >
                      > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                      > news:eTwFu0SxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=green]
                      > > Ah, I wasn't aware alerting the author about changes to the code
                      > > that you've made is a string being attached. The licensing agreement
                      > > at the top is primarily a joke for all those that read it. It even[/color]
                      > requires[color=green]
                      > > that you laugh... I put it there to reduce my own liability and to point
                      > > out that the software isn't supported. Take it for what you will.
                      > >[/color]
                      >
                      > what the "recommende d interpretation" of :
                      >
                      > <quote>
                      > The use of this software is for test and performance purposes only.
                      >
                      > <\quote>
                      >
                      > and
                      >
                      > <quote>
                      > In all seriousness,
                      > excluding the laughter, laughter in itself does not void this license
                      > agreement, nor compromise it's ability to legally bind you.
                      > <\quote>
                      >[color=green]
                      > >
                      > > --
                      > > Justin Rogers
                      > > DigiTec Web Consultants, LLC.
                      > > Blog: http://weblogs.asp.net/justin_rogers
                      > >
                      > > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                      > > news:%23sZN8bSx EHA.2196@TK2MSF TNGP14.phx.gbl. ..[color=darkred]
                      > > >
                      > > > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                      > > > news:uPrrmBSxEH A.1264@TK2MSFTN GP12.phx.gbl...
                      > > >> Apparentyly it whacked the link...
                      > > >>
                      > > >> http://weblogs.asp.net/justin_rogers...es/253641.aspx
                      > > >>
                      > > >>
                      > > >
                      > > > nice - but the code i posted works, begs for a bit of optimization,[/color][/color][/color]
                      but[color=blue][color=green][color=darkred]
                      > > > comes with *no* strings attached.
                      > > >
                      > > > rlf
                      > > >
                      > > >
                      > > >
                      > > >> --
                      > > >> Justin Rogers
                      > > >> DigiTec Web Consultants, LLC.
                      > > >> Blog: http://weblogs.asp.net/justin_rogers
                      > > >>
                      > > >>
                      > > >> "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                      > > >> news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...
                      > > >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for[/color][/color][/color]
                      base2[color=blue][color=green][color=darkred]
                      > > > through
                      > > >> > base36.
                      > > >> >
                      > > >> > The notes are extensive as to the direction the library may or may[/color][/color]
                      > not[color=green][color=darkred]
                      > > > go
                      > > >> > depending on what
                      > > >> > problems people are trying to solve. What I've realized is that[/color][/color][/color]
                      there[color=blue][color=green][color=darkred]
                      > > > are a
                      > > >> > number of additional
                      > > >> > and interesting problems associated with alphabet encoding, such as
                      > > >> > permuations, cyclic
                      > > >> > rotations, error correction, and the like that may be interesting[/color][/color][/color]
                      to[color=blue][color=green][color=darkred]
                      > > > build
                      > > >> > into the libraries. An
                      > > >> > example of an error correction alphabet would be the base32[/color][/color][/color]
                      encoding[color=blue][color=green][color=darkred]
                      > > > which
                      > > >> > removes
                      > > >> > characters that may be confused for other characters when read by a
                      > > > human.
                      > > >> >
                      > > >> >
                      > > >> > --
                      > > >> > Justin Rogers
                      > > >> > DigiTec Web Consultants, LLC.
                      > > >> > Blog: http://weblogs.asp.net/justin_rogers
                      > > >> >
                      > > >> > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                      > > >> > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...
                      > > >> >> William
                      > > >> >>
                      > > >> >> The other base was base 26 and used *just* the uppercase[/color][/color][/color]
                      alphabetic[color=blue][color=green][color=darkred]
                      > > >> >> characters (A..Z). The only change would be to specify the token[/color][/color]
                      > set[color=green][color=darkred]
                      > > > of the
                      > > >> >> number set and the weights of each position. For the Base26 case,[/color][/color]
                      > it[color=green][color=darkred]
                      > > > was
                      > > >> >> this:
                      > > >> >>
                      > > >> >> /* *************** ** */
                      > > >> >> public class BASE32{
                      > > >> >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                      > > >> >> static long [] powers =
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=blue][color=green][color=darkred]
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                      > > >> >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                      > > >> >> ...
                      > > >> >> ...
                      > > >> >> }
                      > > >> >> /* *************** ** */
                      > > >> >>
                      > > >> >> conversion is each direction is based on the tokens and powers[/color][/color]
                      > arrays.[color=green][color=darkred]
                      > > > the
                      > > >> >> first entry in the tokens aray always corresponds to the empty or[/color][/color]
                      > zero[color=green][color=darkred]
                      > > >> >> value, etc.
                      > > >> >>
                      > > >> >> happy to help
                      > > >> >> roy
                      > > >> >>
                      > > >> >>
                      > > >> >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                      > > >> >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                      > > >> >>> Hey thanks a lot Roy. Care to post the other base as well?[/color][/color][/color]
                      Either[color=blue][color=green][color=darkred]
                      > > > way,
                      > > >> >>> thanks again!!
                      > > >> >>>
                      > > >> >>> --
                      > > >> >>> William Stacey, MVP
                      > > >> >>> http://mvp.support.microsoft.com
                      > > >> >>>
                      > > >> >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                      > > >> >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                      > > >> >>> > William,
                      > > >> >>> >
                      > > >> >>> > this is something that i did some time ago - actually for a
                      > > > different
                      > > >> >>> base,
                      > > >> >>> > but it was easy enough to change to handle base32.
                      > > >> >>> >
                      > > >> >>> > you did not specify the symbol set for your number base - i[/color][/color][/color]
                      will[color=blue][color=green][color=darkred]
                      > > > assume
                      > > >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens[/color][/color]
                      > string[color=green][color=darkred]
                      > > >> >>> > accordingly.
                      > > >> >>> >
                      > > >> >>> > for performance reasons, the weights of the digits are computed[/color][/color]
                      > at[color=green][color=darkred]
                      > > >> >> compile
                      > > >> >>> > time.
                      > > >> >>> >
                      > > >> >>> > note - there is absolutely no error checking, and it handles[/color][/color][/color]
                      only[color=blue][color=green][color=darkred]
                      > > >> >> positive
                      > > >> >>> > values, and assumes that all character codes are upper case.
                      > > >> >>> >
                      > > >> >>> > regards
                      > > >> >>> > roy fine
                      > > >> >>> >
                      > > >> >>> >
                      > > >> >>> > namespace CONVERSION{
                      > > >> >>> > // handles positive only values up to[/color][/color][/color]
                      4,738,381,338,3 21,616,896 -[color=blue]
                      > 1;[color=green][color=darkred]
                      > > >> >>> > public class BASE32{
                      > > >> >>> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                      > > >> >>> > static long [] powers =
                      > > >> >>> >
                      > > >> >>>
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green][color=darkred]
                      > > >> >>> >
                      > > >> >>>
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                      > > >> >>> >
                      > > >> >>>
                      > > >> >>
                      > > >[/color][/color]
                      >[/color]
                      36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                      > > >> >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                      > > >> >>> >
                      > > >> >>> > public static string ToString(long lval){
                      > > >> >>> > int maxStrLen = powers.Length;
                      > > >> >>> > long curval = lval;
                      > > >> >>> > char [] tb = new char[maxStrLen];
                      > > >> >>> > int outpos = 0;
                      > > >> >>> > for(int i=0; i<maxStrLen; i++){
                      > > >> >>> > long pval = powers[maxStrLen - i - 1];
                      > > >> >>> > int pos = (int)(curval / pval);
                      > > >> >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                      > > >> >>> > curval = curval % pval;
                      > > >> >>> > }
                      > > >> >>> > if(outpos==0) tb[outpos++] = '0';
                      > > >> >>> > return new string(tb,0,out pos).TrimStart( '0');
                      > > >> >>> > }
                      > > >> >>> >
                      > > >> >>> > public static long ToLong(string t){
                      > > >> >>> > long ival = 0;
                      > > >> >>> > char [] tb = t.ToCharArray() ;
                      > > >> >>> > for(int i=0; i<tb.Length; i++){
                      > > >> >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                      > > >> >>> > }
                      > > >> >>> > return ival;
                      > > >> >>> > }
                      > > >> >>> > }
                      > > >> >>> > }
                      > > >> >>> >
                      > > >> >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in[/color][/color][/color]
                      message[color=blue][color=green][color=darkred]
                      > > >> >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                      > > >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
                      > > >> >> routines?
                      > > >> >>> > TIA
                      > > >> >>> > >
                      > > >> >>> > > --
                      > > >> >>> > > William Stacey, MVP
                      > > >> >>> > > http://mvp.support.microsoft.com
                      > > >> >>> > >
                      > > >> >>> >
                      > > >> >>> >
                      > > >> >>>
                      > > >> >>
                      > > >> >>
                      > > >> >
                      > > >> >
                      > > >>
                      > > >>
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]

                      Comment

                      • William Stacey [MVP]

                        #12
                        Re: Base36

                        Thanks Justin. Any chance you could add long and short support, and maybe
                        arbitrary byte[]s? TIA
                        For byte[]s I was thinking just converting each byte to base36, but that
                        results in 2 char min after dec 36. So maybe need to take 4 or 8 bytes at a
                        time and convert to int or long and convert that to a base to leverage the
                        resulting chars better - not sure. Any thoughts?
                        --
                        William Stacey, MVP


                        "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                        news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...[color=blue]
                        > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2[/color]
                        through[color=blue]
                        > base36.
                        >
                        > The notes are extensive as to the direction the library may or may not go
                        > depending on what
                        > problems people are trying to solve. What I've realized is that there are[/color]
                        a[color=blue]
                        > number of additional
                        > and interesting problems associated with alphabet encoding, such as[/color]
                        permuations,[color=blue]
                        > cyclic
                        > rotations, error correction, and the like that may be interesting to build[/color]
                        into[color=blue]
                        > the libraries. An
                        > example of an error correction alphabet would be the base32 encoding which
                        > removes
                        > characters that may be confused for other characters when read by a human.
                        >
                        >
                        > --
                        > Justin Rogers
                        > DigiTec Web Consultants, LLC.
                        > Blog: http://weblogs.asp.net/justin_rogers
                        >
                        > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                        > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=green]
                        > > William
                        > >
                        > > The other base was base 26 and used *just* the uppercase alphabetic
                        > > characters (A..Z). The only change would be to specify the token set of[/color][/color]
                        the[color=blue][color=green]
                        > > number set and the weights of each position. For the Base26 case, it[/color][/color]
                        was[color=blue][color=green]
                        > > this:
                        > >
                        > > /* *************** ** */
                        > > public class BASE32{
                        > > static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                        > > static long [] powers =
                        > >[/color][/color]
                        {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=blue][color=green]
                        > >[/color][/color]
                        26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green]
                        > >[/color][/color]
                        26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green]
                        > > 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                        > > ...
                        > > ...
                        > > }
                        > > /* *************** ** */
                        > >
                        > > conversion is each direction is based on the tokens and powers arrays.[/color][/color]
                        the[color=blue][color=green]
                        > > first entry in the tokens aray always corresponds to the empty or zero
                        > > value, etc.
                        > >
                        > > happy to help
                        > > roy
                        > >
                        > >
                        > > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                        > > news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=darkred]
                        > >> Hey thanks a lot Roy. Care to post the other base as well? Either[/color][/color][/color]
                        way,[color=blue][color=green][color=darkred]
                        > >> thanks again!!
                        > >>
                        > >> --
                        > >> William Stacey, MVP
                        > >> http://mvp.support.microsoft.com
                        > >>
                        > >> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                        > >> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                        > >> > William,
                        > >> >
                        > >> > this is something that i did some time ago - actually for a different
                        > >> base,
                        > >> > but it was easy enough to change to handle base32.
                        > >> >
                        > >> > you did not specify the symbol set for your number base - i will[/color][/color][/color]
                        assume[color=blue][color=green][color=darkred]
                        > >> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
                        > >> > accordingly.
                        > >> >
                        > >> > for performance reasons, the weights of the digits are computed at[/color]
                        > > compile[color=darkred]
                        > >> > time.
                        > >> >
                        > >> > note - there is absolutely no error checking, and it handles only[/color]
                        > > positive[color=darkred]
                        > >> > values, and assumes that all character codes are upper case.
                        > >> >
                        > >> > regards
                        > >> > roy fine
                        > >> >
                        > >> >
                        > >> > namespace CONVERSION{
                        > >> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
                        > >> > public class BASE32{
                        > >> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                        > >> > static long [] powers =
                        > >> >
                        > >>[/color]
                        > >[/color][/color]
                        {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green][color=darkred]
                        > >> >
                        > >>[/color]
                        > >[/color][/color]
                        36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                        > >> >
                        > >>[/color]
                        > >[/color][/color]
                        36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                        > >> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                        > >> >
                        > >> > public static string ToString(long lval){
                        > >> > int maxStrLen = powers.Length;
                        > >> > long curval = lval;
                        > >> > char [] tb = new char[maxStrLen];
                        > >> > int outpos = 0;
                        > >> > for(int i=0; i<maxStrLen; i++){
                        > >> > long pval = powers[maxStrLen - i - 1];
                        > >> > int pos = (int)(curval / pval);
                        > >> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                        > >> > curval = curval % pval;
                        > >> > }
                        > >> > if(outpos==0) tb[outpos++] = '0';
                        > >> > return new string(tb,0,out pos).TrimStart( '0');
                        > >> > }
                        > >> >
                        > >> > public static long ToLong(string t){
                        > >> > long ival = 0;
                        > >> > char [] tb = t.ToCharArray() ;
                        > >> > for(int i=0; i<tb.Length; i++){
                        > >> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                        > >> > }
                        > >> > return ival;
                        > >> > }
                        > >> > }
                        > >> > }
                        > >> >
                        > >> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                        > >> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                        > >> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion[/color]
                        > > routines?[color=darkred]
                        > >> > TIA
                        > >> > >
                        > >> > > --
                        > >> > > William Stacey, MVP
                        > >> > > http://mvp.support.microsoft.com
                        > >> > >
                        > >> >
                        > >> >
                        > >>[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]

                        Comment

                        • Justin Rogers

                          #13
                          Re: Base36

                          > <quote>[color=blue]
                          > The use of this software is for test and performance purposes only.
                          >
                          > <\quote>[/color]

                          That is to prevent users from holding me liable for putting the code
                          directly into a production system and having it fail. Because I don't
                          mention derived works (and this is from my lawyer, I figured I'd
                          give him a call just to make sure) you could put any derived works
                          into a production system.
                          [color=blue]
                          > <quote>
                          > In all seriousness,
                          > excluding the laughter, laughter in itself does not void this license
                          > agreement, nor compromise it's ability to legally bind you.
                          > <\quote>[/color]

                          Lawyer just laughed and noted that such jargon would not make this
                          any more legally binding than me walking up to you on the street and
                          telling you that I'd copyrighted your name and you were no longer
                          allowed to be called Roy. Sorry you took it out of scope.


                          --
                          Justin Rogers
                          DigiTec Web Consultants, LLC.
                          Blog: http://weblogs.asp.net/justin_rogers


                          Comment

                          • Justin Rogers

                            #14
                            Re: Base36

                            I'll go ahead and add some additional types. That is a a fairly easy process. I
                            need to put some thought into the byte array. Base64 encoding uses a special
                            padding character to overcome some of the issues you are noting below.

                            Version 1.1 is posted at the space with all of the base types added.

                            --
                            Justin Rogers
                            DigiTec Web Consultants, LLC.
                            Blog: http://weblogs.asp.net/justin_rogers

                            "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                            news:OTYmxEUxEH A.3336@TK2MSFTN GP11.phx.gbl...[color=blue]
                            > Thanks Justin. Any chance you could add long and short support, and maybe
                            > arbitrary byte[]s? TIA
                            > For byte[]s I was thinking just converting each byte to base36, but that
                            > results in 2 char min after dec 36. So maybe need to take 4 or 8 bytes at a
                            > time and convert to int or long and convert that to a base to leverage the
                            > resulting chars better - not sure. Any thoughts?
                            > --
                            > William Stacey, MVP
                            > http://mvp.support.microsoft.com
                            >
                            > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                            > news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...[color=green]
                            >> Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2[/color]
                            > through[color=green]
                            >> base36.
                            >>
                            >> The notes are extensive as to the direction the library may or may not go
                            >> depending on what
                            >> problems people are trying to solve. What I've realized is that there are[/color]
                            > a[color=green]
                            >> number of additional
                            >> and interesting problems associated with alphabet encoding, such as[/color]
                            > permuations,[color=green]
                            >> cyclic
                            >> rotations, error correction, and the like that may be interesting to build[/color]
                            > into[color=green]
                            >> the libraries. An
                            >> example of an error correction alphabet would be the base32 encoding which
                            >> removes
                            >> characters that may be confused for other characters when read by a human.
                            >>
                            >>
                            >> --
                            >> Justin Rogers
                            >> DigiTec Web Consultants, LLC.
                            >> Blog: http://weblogs.asp.net/justin_rogers
                            >>
                            >> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                            >> news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...[color=darkred]
                            >> > William
                            >> >
                            >> > The other base was base 26 and used *just* the uppercase alphabetic
                            >> > characters (A..Z). The only change would be to specify the token set of[/color][/color]
                            > the[color=green][color=darkred]
                            >> > number set and the weights of each position. For the Base26 case, it[/color][/color]
                            > was[color=green][color=darkred]
                            >> > this:
                            >> >
                            >> > /* *************** ** */
                            >> > public class BASE32{
                            >> > static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                            >> > static long [] powers =
                            >> >[/color][/color]
                            > {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=green][color=darkred]
                            >> >[/color][/color]
                            > 26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=green][color=darkred]
                            >> >[/color][/color]
                            > 26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=green][color=darkred]
                            >> > 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                            >> > ...
                            >> > ...
                            >> > }
                            >> > /* *************** ** */
                            >> >
                            >> > conversion is each direction is based on the tokens and powers arrays.[/color][/color]
                            > the[color=green][color=darkred]
                            >> > first entry in the tokens aray always corresponds to the empty or zero
                            >> > value, etc.
                            >> >
                            >> > happy to help
                            >> > roy
                            >> >
                            >> >
                            >> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                            >> > news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                            >> >> Hey thanks a lot Roy. Care to post the other base as well? Either[/color][/color]
                            > way,[color=green][color=darkred]
                            >> >> thanks again!!
                            >> >>
                            >> >> --
                            >> >> William Stacey, MVP
                            >> >> http://mvp.support.microsoft.com
                            >> >>
                            >> >> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                            >> >> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                            >> >> > William,
                            >> >> >
                            >> >> > this is something that i did some time ago - actually for a different
                            >> >> base,
                            >> >> > but it was easy enough to change to handle base32.
                            >> >> >
                            >> >> > you did not specify the symbol set for your number base - i will[/color][/color]
                            > assume[color=green][color=darkred]
                            >> >> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
                            >> >> > accordingly.
                            >> >> >
                            >> >> > for performance reasons, the weights of the digits are computed at
                            >> > compile
                            >> >> > time.
                            >> >> >
                            >> >> > note - there is absolutely no error checking, and it handles only
                            >> > positive
                            >> >> > values, and assumes that all character codes are upper case.
                            >> >> >
                            >> >> > regards
                            >> >> > roy fine
                            >> >> >
                            >> >> >
                            >> >> > namespace CONVERSION{
                            >> >> > // handles positive only values up to 4,738,381,338,3 21,616,896 - 1;
                            >> >> > public class BASE32{
                            >> >> > static string tokens = "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";
                            >> >> > static long [] powers =
                            >> >> >
                            >> >>
                            >> >[/color][/color]
                            > {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=green][color=darkred]
                            >> >> >
                            >> >>
                            >> >[/color][/color]
                            > 36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
                            >> >> >
                            >> >>
                            >> >[/color][/color]
                            > 36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=green][color=darkred]
                            >> >> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                            >> >> >
                            >> >> > public static string ToString(long lval){
                            >> >> > int maxStrLen = powers.Length;
                            >> >> > long curval = lval;
                            >> >> > char [] tb = new char[maxStrLen];
                            >> >> > int outpos = 0;
                            >> >> > for(int i=0; i<maxStrLen; i++){
                            >> >> > long pval = powers[maxStrLen - i - 1];
                            >> >> > int pos = (int)(curval / pval);
                            >> >> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                            >> >> > curval = curval % pval;
                            >> >> > }
                            >> >> > if(outpos==0) tb[outpos++] = '0';
                            >> >> > return new string(tb,0,out pos).TrimStart( '0');
                            >> >> > }
                            >> >> >
                            >> >> > public static long ToLong(string t){
                            >> >> > long ival = 0;
                            >> >> > char [] tb = t.ToCharArray() ;
                            >> >> > for(int i=0; i<tb.Length; i++){
                            >> >> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                            >> >> > }
                            >> >> > return ival;
                            >> >> > }
                            >> >> > }
                            >> >> > }
                            >> >> >
                            >> >> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                            >> >> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                            >> >> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
                            >> > routines?
                            >> >> > TIA
                            >> >> > >
                            >> >> > > --
                            >> >> > > William Stacey, MVP
                            >> >> > > http://mvp.support.microsoft.com
                            >> >> > >
                            >> >> >
                            >> >> >
                            >> >>
                            >> >
                            >> >[/color]
                            >>
                            >>[/color]
                            >[/color]


                            Comment

                            • Roy Fine

                              #15
                              Re: Base36

                              William,

                              With your new base of 26+26+10=62, the max range for 5 digits is now 26^5 -
                              1, or 916,132,831.

                              max long is 9,223,372,036,8 54,775,807. Seems that what you are looking for
                              is 5 digits of some base that get close to max long. In other words, x^5 =
                              y, where y = 9,223,372,036,8 54,775,807.
                              Solving for x, we get ln(x) = ln(9,223,372,03 6,854,775,807) / 5, or
                              x = e^(ln(9,223,372 ,036,854,775,80 7) / 5),
                              or x = 6,208. Base 6208 is not easily representable with our standard
                              VT-100 vintage keyboards :(

                              I can find roughly 84 usable characters on my keyboard - the biggest number
                              that I can express in Base78 is 4,182,119,423. Here is the corresponding
                              code:

                              static string tokens =
                              "0123456789!@#$ %^&*()_+=-<>?/.,:;abcdefghijk lmnopqrstuvwxyz ABCDEFGHIJKLMNO PQ
                              RSTUVWXYZ";
                              static long [] powers =
                              {1L,84L,84L*84L ,84L*84L*84L,84 L*84L*84L*84L,8 4L*84L*84L*84L* 84L,84L*84L*84L *
                              84L*84L*84L,84L *84L*84L*84L*84 L*84L*84L,84L*8 4L*84L*84L*84L* 84L*84L*84L,84L *
                              84L*84L*84L*84L *84L*84L*84L*84 L};

                              But - I don't think you want all those silly characters in the product key.

                              If you want to map 5 characters to a number in the range of
                              (0..long.MaxVal ue), consider using base 36 (0..9,A..Z) to represent a seed
                              value, then use that seed in a simple random number generator (of linear
                              congruential type). In its simplest form, the expansion could be nothing
                              more than:
                              ulong sval = x*84589UL+45989 UL;

                              where x is the value from the 5 Base36 characters, and sval is some really
                              big number:

                              /* *************** ************** */
                              string tstr = "ZZZZZ";
                              ulong x = CONVERSION.BASE .ToLong(tstr);
                              ulong sval = x*84589UL+45989 UL;
                              Console.WriteLi ne("real big value: {0}",sval);
                              /* *************** ************** */

                              As you quickly see, this is a one way mapping - i.e. not a symmetrical
                              process.

                              If you want more control over the generation - rather you want a bit more
                              randomness that is not as easily recognizable, consider a 28 or 32 bit
                              linear feedback shift register (if 32, then consider taps at 32,7,5,3,2,1
                              and 0). Load the value from the base 36 representation as the initial
                              condition, and then shift out as much precision as you need (64 shifts gives
                              you the range of 0..long.MaxValu e).

                              I don't know if this helps - but it is an interesting exercise.

                              regards
                              roy fine


                              "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                              news:useetjTxEH A.1300@TK2MSFTN GP14.phx.gbl...[color=blue]
                              > Thanks Roy. Could you expand the range by also including lower case a-z[/color]
                              in[color=blue]
                              > addition to uppercase A-Z?
                              > If so, could you spoon feed me again with the updated logic if possible.
                              > What I am looking to do is:
                              > 1) 5 base chars (0..9, a...z, A..Z) for count - max range up to
                              > long.MaxRange if possible. Right now max range of ZZZZZ is 60,466,175.
                              > 2) Take a hash of count + some secret string(s) using PasswordDeriveB ytes
                              > and convert as many bytes as possible to an alpha base encoding for a max[/color]
                              of[color=blue]
                              > "HHHH-HHHH-HHHC-CCCC" (five Count positions and 11 Hash positions) to get[/color]
                              a[color=blue]
                              > Product key (e.g. MSs). I should be able to recalc the hash at the client
                              > using stripped out count and the shared secret to verify the calculated[/color]
                              hash[color=blue]
                              > matches the hash in the Product Key supplied. May need to break the hash
                              > bytes into two longs (16 bytes) and maybe clear high order byte before the
                              > conversion to long so I can pass each long to the BaseXX converter to get
                              > the string. Right now I can do 7 bytes and be sure to stay in
                              > 473838133832161 6895 range.
                              >
                              > I realize the secret is vulnerable, but think I can make it good enouph[/color]
                              for[color=blue]
                              > my needs as just an activation code. Anyway, hope above makes some sense.
                              > Basically looking to encode bigger ranges (max longs or max ulongs, or
                              > doubles if possible) with as few chars as possible in the valid set. Many
                              > thanks again. Cheers.
                              >
                              > --
                              > William Stacey, MVP
                              > http://mvp.support.microsoft.com
                              >
                              > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                              > news:u79ypMTxEH A.1396@tk2msftn gp13.phx.gbl...[color=green]
                              > >
                              > > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                              > > news:eTwFu0SxEH A.3908@TK2MSFTN GP12.phx.gbl...[color=darkred]
                              > > > Ah, I wasn't aware alerting the author about changes to the code
                              > > > that you've made is a string being attached. The licensing agreement
                              > > > at the top is primarily a joke for all those that read it. It even[/color]
                              > > requires[color=darkred]
                              > > > that you laugh... I put it there to reduce my own liability and to[/color][/color][/color]
                              point[color=blue][color=green][color=darkred]
                              > > > out that the software isn't supported. Take it for what you will.
                              > > >[/color]
                              > >
                              > > what the "recommende d interpretation" of :
                              > >
                              > > <quote>
                              > > The use of this software is for test and performance purposes only.
                              > >
                              > > <\quote>
                              > >
                              > > and
                              > >
                              > > <quote>
                              > > In all seriousness,
                              > > excluding the laughter, laughter in itself does not void this license
                              > > agreement, nor compromise it's ability to legally bind you.
                              > > <\quote>
                              > >[color=darkred]
                              > > >
                              > > > --
                              > > > Justin Rogers
                              > > > DigiTec Web Consultants, LLC.
                              > > > Blog: http://weblogs.asp.net/justin_rogers
                              > > >
                              > > > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                              > > > news:%23sZN8bSx EHA.2196@TK2MSF TNGP14.phx.gbl. ..
                              > > > >
                              > > > > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                              > > > > news:uPrrmBSxEH A.1264@TK2MSFTN GP12.phx.gbl...
                              > > > >> Apparentyly it whacked the link...
                              > > > >>
                              > > > >> http://weblogs.asp.net/justin_rogers...es/253641.aspx
                              > > > >>
                              > > > >>
                              > > > >
                              > > > > nice - but the code i posted works, begs for a bit of optimization,[/color][/color]
                              > but[color=green][color=darkred]
                              > > > > comes with *no* strings attached.
                              > > > >
                              > > > > rlf
                              > > > >
                              > > > >
                              > > > >
                              > > > >> --
                              > > > >> Justin Rogers
                              > > > >> DigiTec Web Consultants, LLC.
                              > > > >> Blog: http://weblogs.asp.net/justin_rogers
                              > > > >>
                              > > > >>
                              > > > >> "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                              > > > >> news:Om9Pw9RxEH A.1260@TK2MSFTN GP12.phx.gbl...
                              > > > >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for[/color][/color]
                              > base2[color=green][color=darkred]
                              > > > > through
                              > > > >> > base36.
                              > > > >> >
                              > > > >> > The notes are extensive as to the direction the library may or[/color][/color][/color]
                              may[color=blue][color=green]
                              > > not[color=darkred]
                              > > > > go
                              > > > >> > depending on what
                              > > > >> > problems people are trying to solve. What I've realized is that[/color][/color]
                              > there[color=green][color=darkred]
                              > > > > are a
                              > > > >> > number of additional
                              > > > >> > and interesting problems associated with alphabet encoding, such[/color][/color][/color]
                              as[color=blue][color=green][color=darkred]
                              > > > >> > permuations, cyclic
                              > > > >> > rotations, error correction, and the like that may be interesting[/color][/color]
                              > to[color=green][color=darkred]
                              > > > > build
                              > > > >> > into the libraries. An
                              > > > >> > example of an error correction alphabet would be the base32[/color][/color]
                              > encoding[color=green][color=darkred]
                              > > > > which
                              > > > >> > removes
                              > > > >> > characters that may be confused for other characters when read by[/color][/color][/color]
                              a[color=blue][color=green][color=darkred]
                              > > > > human.
                              > > > >> >
                              > > > >> >
                              > > > >> > --
                              > > > >> > Justin Rogers
                              > > > >> > DigiTec Web Consultants, LLC.
                              > > > >> > Blog: http://weblogs.asp.net/justin_rogers
                              > > > >> >
                              > > > >> > "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                              > > > >> > news:unkF9yRxEH A.2192@TK2MSFTN GP14.phx.gbl...
                              > > > >> >> William
                              > > > >> >>
                              > > > >> >> The other base was base 26 and used *just* the uppercase[/color][/color]
                              > alphabetic[color=green][color=darkred]
                              > > > >> >> characters (A..Z). The only change would be to specify the[/color][/color][/color]
                              token[color=blue][color=green]
                              > > set[color=darkred]
                              > > > > of the
                              > > > >> >> number set and the weights of each position. For the Base26[/color][/color][/color]
                              case,[color=blue][color=green]
                              > > it[color=darkred]
                              > > > > was
                              > > > >> >> this:
                              > > > >> >>
                              > > > >> >> /* *************** ** */
                              > > > >> >> public class BASE32{
                              > > > >> >> static string tokens = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
                              > > > >> >> static long [] powers =
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              {1L,26L,26L*26L ,26L*26L*26L,26 L*26L*26L*26L,2 6L*26L*26L*26L* 26L,26L*26L*26L *[color=blue][color=green][color=darkred]
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              26L*26L*26L,26L *26L*26L*26L*26 L*26L*26L,26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              26L*26L*26L*26L *26L*26L*26L*26 L,26L*26L*26L*2 6L*26L*26L*26L* 26L*26L*26L,26L *[color=blue][color=green][color=darkred]
                              > > > >> >> 26L*26L*26L*26L *26L*26L*26L*26 L*26L*26L};
                              > > > >> >> ...
                              > > > >> >> ...
                              > > > >> >> }
                              > > > >> >> /* *************** ** */
                              > > > >> >>
                              > > > >> >> conversion is each direction is based on the tokens and powers[/color]
                              > > arrays.[color=darkred]
                              > > > > the
                              > > > >> >> first entry in the tokens aray always corresponds to the empty[/color][/color][/color]
                              or[color=blue][color=green]
                              > > zero[color=darkred]
                              > > > >> >> value, etc.
                              > > > >> >>
                              > > > >> >> happy to help
                              > > > >> >> roy
                              > > > >> >>
                              > > > >> >>
                              > > > >> >> "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in message
                              > > > >> >> news:u$MPFPQxEH A.3908@TK2MSFTN GP12.phx.gbl...
                              > > > >> >>> Hey thanks a lot Roy. Care to post the other base as well?[/color][/color]
                              > Either[color=green][color=darkred]
                              > > > > way,
                              > > > >> >>> thanks again!!
                              > > > >> >>>
                              > > > >> >>> --
                              > > > >> >>> William Stacey, MVP
                              > > > >> >>> http://mvp.support.microsoft.com
                              > > > >> >>>
                              > > > >> >>> "Roy Fine" <rlfine@twt.obf uscate.net> wrote in message
                              > > > >> >>> news:#wPFSCQxEH A.3976@TK2MSFTN GP09.phx.gbl...
                              > > > >> >>> > William,
                              > > > >> >>> >
                              > > > >> >>> > this is something that i did some time ago - actually for a
                              > > > > different
                              > > > >> >>> base,
                              > > > >> >>> > but it was easy enough to change to handle base32.
                              > > > >> >>> >
                              > > > >> >>> > you did not specify the symbol set for your number base - i[/color][/color]
                              > will[color=green][color=darkred]
                              > > > > assume
                              > > > >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens[/color]
                              > > string[color=darkred]
                              > > > >> >>> > accordingly.
                              > > > >> >>> >
                              > > > >> >>> > for performance reasons, the weights of the digits are[/color][/color][/color]
                              computed[color=blue][color=green]
                              > > at[color=darkred]
                              > > > >> >> compile
                              > > > >> >>> > time.
                              > > > >> >>> >
                              > > > >> >>> > note - there is absolutely no error checking, and it handles[/color][/color]
                              > only[color=green][color=darkred]
                              > > > >> >> positive
                              > > > >> >>> > values, and assumes that all character codes are upper case.
                              > > > >> >>> >
                              > > > >> >>> > regards
                              > > > >> >>> > roy fine
                              > > > >> >>> >
                              > > > >> >>> >
                              > > > >> >>> > namespace CONVERSION{
                              > > > >> >>> > // handles positive only values up to[/color][/color]
                              > 4,738,381,338,3 21,616,896 -[color=green]
                              > > 1;[color=darkred]
                              > > > >> >>> > public class BASE32{
                              > > > >> >>> > static string tokens =[/color][/color][/color]
                              "0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ";[color=blue][color=green][color=darkred]
                              > > > >> >>> > static long [] powers =
                              > > > >> >>> >
                              > > > >> >>>
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              {1L,36L,36L*36L ,36L*36L*36L,36 L*36L*36L*36L,3 6L*36L*36L*36L* 36L,36L*36L*36L *[color=blue][color=green][color=darkred]
                              > > > >> >>> >
                              > > > >> >>>
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              36L*36L*36L,36L *36L*36L*36L*36 L*36L*36L,36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                              > > > >> >>> >
                              > > > >> >>>
                              > > > >> >>
                              > > > >[/color]
                              > >[/color]
                              >[/color]
                              36L*36L*36L*36L *36L*36L*36L*36 L,36L*36L*36L*3 6L*36L*36L*36L* 36L*36L*36L,36L *[color=blue][color=green][color=darkred]
                              > > > >> >>> > 36L*36L*36L*36L *36L*36L*36L*36 L*36L*36L};
                              > > > >> >>> >
                              > > > >> >>> > public static string ToString(long lval){
                              > > > >> >>> > int maxStrLen = powers.Length;
                              > > > >> >>> > long curval = lval;
                              > > > >> >>> > char [] tb = new char[maxStrLen];
                              > > > >> >>> > int outpos = 0;
                              > > > >> >>> > for(int i=0; i<maxStrLen; i++){
                              > > > >> >>> > long pval = powers[maxStrLen - i - 1];
                              > > > >> >>> > int pos = (int)(curval / pval);
                              > > > >> >>> > tb[outpos++] = tokens.Substrin g(pos,1).ToChar Array()[0];
                              > > > >> >>> > curval = curval % pval;
                              > > > >> >>> > }
                              > > > >> >>> > if(outpos==0) tb[outpos++] = '0';
                              > > > >> >>> > return new string(tb,0,out pos).TrimStart( '0');
                              > > > >> >>> > }
                              > > > >> >>> >
                              > > > >> >>> > public static long ToLong(string t){
                              > > > >> >>> > long ival = 0;
                              > > > >> >>> > char [] tb = t.ToCharArray() ;
                              > > > >> >>> > for(int i=0; i<tb.Length; i++){
                              > > > >> >>> > ival += powers[i]*tokens.IndexOf (tb[tb.Length-i-1]);
                              > > > >> >>> > }
                              > > > >> >>> > return ival;
                              > > > >> >>> > }
                              > > > >> >>> > }
                              > > > >> >>> > }
                              > > > >> >>> >
                              > > > >> >>> > "William Stacey [MVP]" <staceywREMOVE@ mvps.org> wrote in[/color][/color]
                              > message[color=green][color=darkred]
                              > > > >> >>> > news:uc3%23MkOx EHA.1988@TK2MSF TNGP12.phx.gbl. ..
                              > > > >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10[/color][/color][/color]
                              conversion[color=blue][color=green][color=darkred]
                              > > > >> >> routines?
                              > > > >> >>> > TIA
                              > > > >> >>> > >
                              > > > >> >>> > > --
                              > > > >> >>> > > William Stacey, MVP
                              > > > >> >>> > > http://mvp.support.microsoft.com
                              > > > >> >>> > >
                              > > > >> >>> >
                              > > > >> >>> >
                              > > > >> >>>
                              > > > >> >>
                              > > > >> >>
                              > > > >> >
                              > > > >> >
                              > > > >>
                              > > > >>
                              > > > >
                              > > > >
                              > > >
                              > > >[/color]
                              > >
                              > >[/color]
                              >[/color]


                              Comment

                              Working...