C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 19th, 2006, 11:50 AM
level4 level4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 58 level4 User rank is Private First Class (20 - 50 Reputation Level)level4 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 15 h 40 m 2 sec
Reputation Power: 7
Send a message via ICQ to level4
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?

Reply With Quote
  #2  
Old July 19th, 2006, 12:23 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,252 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
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';

Reply With Quote
  #3  
Old July 19th, 2006, 12:37 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,905 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
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?
Comments on this post
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

Reply With Quote
  #4  
Old July 19th, 2006, 10:11 PM
ComputerPhreak's Avatar
ComputerPhreak ComputerPhreak is offline
Super User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 648 ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
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?"

Reply With Quote
  #5  
Old July 21st, 2006, 04:15 AM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
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

Reply With Quote
  #6  
Old July 21st, 2006, 10:57 AM
Devorius Devorius is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 48 Devorius User rank is Corporal (100 - 500 Reputation Level)Devorius User rank is Corporal (100 - 500 Reputation Level)Devorius User rank is Corporal (100 - 500 Reputation Level)Devorius User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 15 h 29 m 4 sec
Reputation Power: 9
itoa()

Reply With Quote
  #7  
Old July 21st, 2006, 11:27 AM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Fastest way decimal to segment in chars

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap