Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/06/04 11:35
Read: times


 
#69931 - RE: Convert int to a string
Responding to: ???'s previous message
From your code, it seems that your require to convert a float to a string in the format:

abc.d

Where abc is not greater than 255 and leading zeros are to be replaced by spaces.

In which case, although your code looks a little awkward, I don't think that it can be very much improved speed wise. If you are using Keil, then I know that division and modulus operations on char size variables is very quick.

In any case, I assume that your main objection to prrintf is its speed.

I do not that current does not get rounded. This could easily be done by adding 0.05 to current.

If you want a bit more flexibility - personally I think that would be a good idea - then I would multiply current by 10^n and then do a regular radix conversion.

If you are using Keil, my conversion function can be used:

http://www.programmersheaven.com/zone5/cat.../32302.htm

If you are not using Keil, this function can prbably still be converted to work with your compiler, but that will be a little more of a chalenge.

The long int returned by fast_binary_to_bcd() contains the 8 least significant BCD digits of the argument. All that then remains to do it to extract each BCD digit with successive shifts of four bits.

If you really need speed, an int sized version of fast_binary_to_bcd() could be generated. My guess is that this is the only way you would get a function significantly faster than the one you already have.

If you are using Keil, my fast shift and roll functions may be of interest, see here:

http://www.programmersheaven.com/zone5/cat.../31937.htm

All that then remains is to suppress leading zeros and put the decimal point in the right place.

List of 12 messages in thread
TopicAuthorDate
Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: float to ascii            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
      RE: Convert int to a string            01/01/70 00:00      
   Back to basics            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      
      RE: Convert int to a string            01/01/70 00:00      
         RE: Convert int to a string            01/01/70 00:00      
   RE: Convert int to a string            01/01/70 00:00      

Back to Subject List