Jump to content
  • Advertisement
Sign in to follow this  
lincsimp

representing number

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi I've a strange problem (not a school task). How can I reprenesnt a number eg.13278 as the shortest possible string. If n is the number of possibilities for each character I guess I would need to create a base n number system. Am I correct? I can't remember much high school math.... cheers

Share this post


Link to post
Share on other sites
Advertisement
For an ASCII string, you have an upper limit of base 256, as each character can represent a digit 0-255. Don't expect this string to be human readable. The number of human readable characters is somewhere around 150 I am guessing.

This is somewhat of a unique question. For what purpose do you need to store these numbers?

Share this post


Link to post
Share on other sites
Yes, you would create a base N number system. The larger the value of N, the less digits the number will have. The number of digits in the value x in base N is floor( logN x ) + 1.

Share this post


Link to post
Share on other sites
To represent 13278 you'd only need 2 8-bit characters (2^16 = 65536), this is also how a normal binary integer representation works.
However, not that not all of these ASCII characters can be used "safely". So for pratical purposes most text encodings of binary data (such as uuencode) limit themselves to using at most 6-bits per character (64 safe characters).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!