System.Int32.CreateString C# (CSharp) Method

CreateString() static private method

static private CreateString ( uint value, bool signed, bool hex ) : string
value uint
signed bool
hex bool
return string
        internal static unsafe string CreateString(uint value, bool signed, bool hex)
        {
            int offset = 0;

            uint uvalue = value;
            ushort divisor = hex ? (ushort)16 : (ushort)10;
            int length = 0;
            int count = 0;
            uint temp;
            bool negative = false;

            if (value < 0 && !hex && signed)
            {
                count++;
                uvalue = (uint)-value;
                negative = true;
            }

            temp = uvalue;

            do
            {
                temp /= divisor;
                count++;
            }
            while (temp != 0);

            length = count;
            String result = String.InternalAllocateString(length);

            char* chars = result.first_char;

            if (negative)
            {
                *(chars + offset) = '-';
                offset++;
                count--;
            }

            for (int i = 0; i < count; i++)
            {
                uint remainder = uvalue % divisor;

                if (remainder < 10)
                    *(chars + offset + count - 1 - i) = (char)('0' + remainder);
                else
                    *(chars + offset + count - 1 - i) = (char)('A' + remainder - 10);

                uvalue /= divisor;
            }

            return result;
        }