|
-
August 21st, 2003, 01:48 PM
#1
Problems converting a string to a Uint16
I'm trying to convert std::string to a Uint16 and I'm having problems... Here's what I'm doing...
Code:
std::string str = "111111111";
Uint16 myInt = atoi(str.c_str()); // myInt becomes 27591 !!
Am I mixing up Uints & ints...strings & CStrings?? I'm sooo confused....
-
August 21st, 2003, 02:13 PM
#2
What is a Uint16 ???
is it an unsigned short ? (16 bits)
if so the range of values it can hold is 0 to 65535
instead of Unit16, use int and it should work.
-
August 21st, 2003, 03:41 PM
#3
Just to beat the dead horse,
(111111111 % 65536) = 27591
so your code is correct to the precision of an unsigned 16-bit integer. Like Phillip said, if you want more than 65535, you should use an int.
[edit] Err, well, I guess you would use a Uint32 [/edit]
Bassman
-
August 22nd, 2003, 07:53 AM
#4
Thanks for the help! Seems I was using the "11111111" for test data in my app and I neglected to take into consideration the 65xxx limit of the 16 bit int. **sigh** Musta been a loooooong day! Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|