bigloo.foreign.integer_to_string C# (CSharp) Method

integer_to_string() public static method

public static integer_to_string ( int n, int radix ) : byte[]
n int
radix int
return byte[]
        public static byte[] integer_to_string( int n, int radix )
        {
            // !!!!! beware: the following code is almost the same than in the next function !!!!!
            if (radix == 10)
               return getbytes( n.ToString( "d" ) );
            else
            {
               int bits= (n < 0 ? 1 : 0);
               int abs_n= Math.Abs( n );
               int abs_n2= abs_n;

               do
               {
              ++bits;
              abs_n2/= radix;
               }
               while (0 < abs_n2);

               byte[] result= new byte[bits];

               do
               {
              --bits;
              result[bits]= hexa[abs_n % radix];
              abs_n/= radix;
               }
               while (0 < bits);

               if (n < 0)
              result[0]= (byte)'-';

               return result;
            }
        }
foreign