bigloo.foreign.parseinteger C# (CSharp) Method

parseinteger() public static method

public static parseinteger ( byte buf, int initPos, int bout, int radix ) : Object
buf byte
initPos int
bout int
radix int
return Object
        public static Object parseinteger(byte[]buf, int initPos, int bout, int radix)
        {
            int pos = initPos;
            int result = 0;
            bool neg = false;
            int cn;

            if (buf[pos] == (byte) '-')
            {
               ++pos;
               neg = true;
            }
            if (buf[pos] == (byte) '+')
            {
               ++pos;
               neg = false;
            }

            while (pos < bout)
            {
               cn = charDigit2Val( buf[pos] );

               if( result > MAX_VALUE_FX / radix - cn ) {
              long lresult = result;
              while (pos < bout)
              {
             cn = charDigit2Val( buf[pos++] );
             if ( lresult > MAX_VALUE_ELONG / radix - cn ) {
            byte[] sbuf = new byte[ bout - initPos ];
                return bgl_string_to_bignum( newstring(buf, initPos, bout - initPos), radix );
             }

             lresult = lresult * radix + cn;
             pos++;
              }
              return LLONG_TO_BLLONG(neg ? -lresult : lresult);
               } else {
              result = result * radix + cn;
              pos++;
               }
            }

            return BINT(neg ? -result : result);
        }
foreign