469,601 Members | 2,309 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

UInt16 - scanf format specifier "%hd" = loss of precision?

Hello - I am looking at a scanf function that takes in a 16 bit unsigned int(UINT16), but its format specifier is %hd. According to

http://publib.boulder.ibm.com/infoce...specifiers.htm

that specifier is for a short int, so won't I lose precision here?

Also - %hd is for base 8. I am confused about bases. Is UInt16 base 16 or how does that work??

Thanks!!

p.s the code looks like this
Expand|Select|Wrap|Line Numbers
  1. UNIT16 varA;
  2. more code here...
  3. scanf("%hd", &varA);
  4.  
Jul 22 '08 #1
1 15461
Banfa
9,064 Expert Mod 8TB
h specifies short int or unsigned short int depending on what follows.
%hd is for short int in base 10, %ho would be for unsigned short int in base 8, read the page you referenced.
For a UInt16 you would want unsigned short int the specifier would be %hu again this is on the page you referenced. If you used %hd you would loose 1 bit of precision but you would also get large value integers from negative input.

It is a good idea when you have looked up information to then actually read it.
Jul 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Pablo J Royo | last post: by
9 posts views Thread by Brad Ford | last post: by
235 posts views Thread by napi | last post: by
7 posts views Thread by Irakl Gordin | last post: by
2 posts views Thread by HD | last post: by
10 posts views Thread by Kobu | last post: by
7 posts views Thread by Rajesh S R | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.