Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
July 19th, 2006, 11:50 AM
 level4
Contributing User

Join Date: Jul 2006
Posts: 58
Time spent in forums: 15 h 40 m 2 sec
Reputation Power: 7
Fastest way decimal to segment in chars

Decimal can be representented as:
number=106;
sprintf(str,"%u",number);
str + 0=1;
str + 1=0;
str + 2=6;

any method faster than sprintf?

#2
July 19th, 2006, 12:23 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,252
Time spent in forums: 2 Months 2 Weeks 5 Days 19 h 26 m 40 sec
Reputation Power: 1985
Assembly.

Or maybe if you rolled your own function.

BTW, if by
str + 0=1;
you really meant
str[0]='1';
, then you left out the most important part, the null-terminator:
str[3]='\0';

#3
July 19th, 2006, 12:37 PM
 salem
Contributed User

Join Date: Jun 2005
Posts: 3,905
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 9 m 41 sec
Reputation Power: 1774
How did you determine that sprintf() is the cause of your performance problems?
ComputerPhreak agrees!
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

#4
July 19th, 2006, 10:11 PM
 ComputerPhreak
Super User

Join Date: Sep 2004
Posts: 648
Time spent in forums: 6 Days 21 h 32 m 25 sec
Reputation Power: 74
Quote:
 Originally Posted by level4 any method faster than sprintf?

The answer to that question is "Yes." However, as salem suggested, the real question that needs to be answered is "Is it worth it to invest in optimizing this portion of my program?"

#5
July 21st, 2006, 04:15 AM
 peenie

Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Read through this thread, there are quite a few good ideas there.
__________________
OMG RAVER CHICKS!!
On a related note: C/C++ Programming Tutorials

"Science is based on reality staying the same, and Nature ignores what humans vote upon." -- Bill Beaty
"Three litres of sherry up the butt can only be described as astounding." -- Darwin Awards

#6
July 21st, 2006, 10:57 AM
 Devorius
Contributing User

Join Date: May 2006
Posts: 48
Time spent in forums: 4 Days 15 h 29 m 4 sec
Reputation Power: 9
itoa()

#7
July 21st, 2006, 11:27 AM
 peenie

Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Quote:
 Originally Posted by dwise1_aol Assembly.

I feel like I've seen some interesting assembler algorithms for converting base 256 to base 10 (ones that aren't just divide with remainder repeatedly); but I don't think any of them used any "special" instructions like ror or anything, so you should be able to write C code that compiles to the exact same thing. Can't remember though.

Quote:
 Originally Posted by Devorious itoa()

That's probably the best bet since any function you rolled yourself would most likely use the same algorithm. But itoa() is deprecated in POSIX (for security reasons; same reason that gets() is unsafe), and so it's not really portable. MS compilers support it (with the underscore, _itoa), but it's not in the version of glibc I have on this machine, at least.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Fastest way decimal to segment in chars

## Developer Shed Advertisers and Affiliates

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |