FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
December 01, 2002
Flexible C++ #1: Efficient Integer to String Conversions

(Page 1 of 6)
Matthew Wilson
The fastest to_string in town.
December 2002/C/C++ Tip #10: Efficient Integer to String Conversions/Listing 1

Listing 1: Unsigned integer conversion

/* /////////////////////////////////////////////////////////////
 *
 * ...
 *
 * Extract from stlsoft_integer_to_string.h
 *
 * www:        http://www.synesis.com.au/stlsoft
 *             http://www.stlsoft.org/
 *
 * Copyright (C) 2002, Synesis Software Pty Ltd.
 * (Licensed under the Synesis Software Standard Source License:
 *  http://www.synesis.com.au/licenses/ssssl.html)
 *
 * ...
 *
 * ////////////////////////////////////////////////////////// */

...

template <class C, class I>
inline const C *unsigned_integer_to_string( C       *buf,
                                            size_t  cchBuf,
                                            I       i)
{
    C   *psz    =   buf + cchBuf - 1;   // Set psz to last char

    *psz = 0;                           // Set terminating null

    do
    {
        unsigned    lsd = i % 10;       // Get least significant
                                        // digit

        i /= 10;                        // Prepare for next most
                                        // significant digit

        --psz;                          // Move back

        *psz = get_digit_character<C>()[lsd]; // Place the digit

    } while(i != 0);

    return psz;
}

— End of Listing —
1 | 2 | 3 | 4 | 5 | 6 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK