Guido Tarsia
Guido Tarsia

Reputation: 2162

What is the size of a character packed integer in comparison with its original size?

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

Answers (3)

KeithS
KeithS

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

ThibThib
ThibThib

Reputation: 8210

log10(T) + 1 will give you the size (in characters) of the string S

Upvotes: 2

BonyT
BonyT

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

Related Questions