On 2007-11-05 10:37:47 -0800, Jon Skeet [C# MVP] <sk***@pobox.co msaid:
Steve <ki****@harpser vices.comwrote:
>I have a registration code that currently has 4 bytes that are unused.
I'd like to store a future date in those 4 bytes. Is there a way to
convert a date to a 4 byte string?
One thing no-one else has mentioned: strings aren't comprised of bytes.
That's true.
They're comprised of *characters*.
That's not. :) A string may _comprise_ characters. It's not
_comprised of_ characters, it's _composed of_ characters.
Sorry, pet peeve. But if people keep misusing "comprise" like that,
we're left with a word that used to be a perfectly useful word but
which is now just a useless synonym for "compose".
I hope your editor doesn't let you get away with stuff like that in
your book. :)
Now, do you need a 4-byte data
structure of any description, or an actual 4 character string?
Now that is a very good point. As is sometimes the case, I and others
have fallen into the trap of assuming the OP has asked a question that
correctly reflects what he really wants to do. But you're right, his
question is ambigious and he should clarify whether he has 4 bytes or 4
characters to use.
Interestingly, if the latter then my personal opinion is that his
options are possibly actually more restricted than if he had 4 bytes.
Though the native .NET String format is 2 bytes per character,
typically one would not want to store invalid characters or characters
that wouldn't be correctly represented in some external storage.
So unless he could guarantee the string (assuming it is really a
string) is stored as some Unicode format, he'd want to limit himself to
at least regular, printable 8-bit characters (e.g. the Windows "ANSI"
or similar), if not to the printable subset of 7-bit ASCII. That
significantly would reduce the possible number of combinations
available below what a regular 32-bit binary data value would allow.
Ah...nothing is ever as simple as it first looks. :)
Pete