Skip to main content
gamedev.net
🔒 Locked

Base conversions

Started by SuperD Aug 5, 2003 at 5:27 PM 4 replies 500+ views
Original Post
SuperD
SuperD
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!
[quote]Never forget that the meaning of life is 42.[/quote]
Sneftel
Sneftel
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.
SuperD
SuperD
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]
[quote]Never forget that the meaning of life is 42.[/quote]
JuNC
JuNC
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.
SuperD
SuperD
Cool, I think I''ll figure out outputing in binary mode...Thanks!
[quote]Never forget that the meaning of life is 42.[/quote]
Thunder_Hawk
Thunder_Hawk
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
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.