Reputation: 2162
Suppose that I
is the size of a T
integer.
What is the maximum size of a string S
that contains the digits of T
arranged into characters?
For example:
T = 12345
S = '12345'
Upvotes: 0
Views: 86
Reputation: 71573
Actually, the basic equation only works for ASCII characters in ASCII or UTF-8 encoding; one byte per character. For UTF-16, these same characters would be encoded as 2 bytes each, and in UTF-32, 4 bytes each. This matters, depending on the programming language and runtime; .NET strings are stored and encoded in UTF-16.
So, it's actually (log(N) + 1)*sizeof(char)
Upvotes: 1
Reputation: 8210
log10(T) + 1
will give you the size (in characters) of the string S
Upvotes: 2
Reputation: 10940
The answer is the log (base10) of I + 1
Thus an int I of 1000 - log I would give you 3 + 1 = 4
Upvotes: 0