representing number

Started by
3 comments, last by doynax 18 years, 8 months ago
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
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?
....[size="1"]Brent Gunning
Thanks, It was just something I was wondering...
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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).

This topic is closed to new replies.

Advertisement