Archived

This topic is now archived and is closed to further replies.

SuperD

Base conversions

Recommended Posts

SuperD    122
How do I convert a double to a base-200 string and back again? The game I''m making uses external levels and it will greatly reduce the file size!

Share this post


Link to post
Share on other sites
Sneftel    1788
How, exactly, do you expect to reduce file size that way? Just store the double as a double; it''s only 8 bytes. If that''s more precision than you need, store it as a float (4 bytes). If you can use fixed-point numbers (integers, possibly with an implied denominator), use them.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
SuperD    122
Well, right now the file is stored in a .map (.txt) file, with 1 byte per character. Storing it normally would use 1 byte per 0-9, decimal, whatever. Converting it to base 200 (starting with the zero character) would allow 0 to whatever character '0' + 200 is, thus making way better use of the byte. If you can think of a better way though, I'm all ears.

Of course, this is in character mode, I do not know how to use binary mode or whatever...is that what you are referring to?

[edited by - SuperD on August 5, 2003 7:09:18 PM]

Share this post


Link to post
Share on other sites
JuNC    236
quote:

Of course, this is in character mode, I do not know how to use binary mode or whatever...is that what you are referring to?



Not to put words in Sneftels mouth, but: yes

There is absolutely no advantage in most situations in doing what you propose. The good thing about files in ASCII is portability, every platform can process ASCII files directly. If you aren''t trying to be portable to can make far better use of binary packing. Simple example:

4.522345 = 8 bytes (ASCII)
4.522345 = 4 bytes (binary float)

However, whether that number can be represented exactly as a float I don''t know (which is always an issue to consider and depends on application).

A better mechanism if you don''t want to use binary would be to use zlib (or similar) to compress the ASCII representation and de-compress on loading.

Share this post


Link to post
Share on other sites
Thunder_Hawk    314
The only real application of this kind of method might be on a calculator where your options are really limited. I kind of discovered base conversions on my own that way. It was a weird feeling when my math teacher starting putting different words to something I had already figured out.

(BTW, I was trying to put multiple characters into each number in a list. It worked perfectly, but it was god-awful slow )

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites