View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
Better Way to Deal With Signed Int |
Posted: Mon Oct 09, 2006 6:02 pm |
|
|
Hello All,
I'm trying to store a value that can range from -1 to 65,535. It will arrive as a string and if the value is -1 then that is a flag otherwise it is a sequence number.
I can make a signed int32 to hold the value but it seems awfully wasteful. Is there a better way to skin the cat or am I making something of nothing? (btw, code space doesn't appear to be a problem yet.)
Thanks,
John |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Oct 09, 2006 6:08 pm |
|
|
An elegant way would be to use a Structure containing an Int16 and a Short or boolean. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Mon Oct 09, 2006 6:14 pm |
|
|
Ahhhh... thanks.
I had thought of using two variables, but thought that was kind of messy. Structures hadn't occured to me because I'm not that familiar with them... I guess it's time to make them my friend.
My general approach will be to check for a '-', and set that bit in the structure if necessary. Then parse the '-' character out of the string and then use the atol function to put the remainder of the srting in the int16 variable.
Sound about right.
Thanks,
John |
|
|
|