Example #1
0
        private static unsafe void ConvertIntegerToString(byte *dest, ref int destIndex, int destLength, long value, FormatOptions options)
        {
            var basis = options.GetBase();

            if (basis < 2 || basis > 36)
            {
                return;
            }

            // Calculate the full length (including zero padding)
            int length = 0;
            var tmp    = value;

            do
            {
                tmp /= basis;
                length++;
            } while (tmp != 0);

            // Write the characters for the numbers to a temp buffer
            byte *tmpBuffer = stackalloc byte[length + 1];

            tmp = value;
            int tmpIndex = length - 1;

            do
            {
                tmpBuffer[tmpIndex--] = ValueToIntegerChar((int)(tmp % basis), options.Uppercase);
                tmp /= basis;
            } while (tmp != 0);
            tmpBuffer[length] = 0;

            var numberBuffer = new NumberBuffer(NumberBufferKind.Integer, tmpBuffer, length, length, value < 0);

            FormatNumber(dest, ref destIndex, destLength, ref numberBuffer, options.Specifier, options);
        }