473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 16917
Banfa
9,065 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

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

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
9
by: Brad Ford | last post by:
I see posts concerning the use of Whidbey, I am new to MSDN, and I would very much like to try it out. There is even a "hands on tutorial", but the requirement is that you have Whidbey installed...
235
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
7
by: Irakl Gordin | last post by:
this.opener is not null but everything inside it is "uknown". How should I interpret it? *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
2
by: HD | last post by:
Hello, Here is my code... <table> <tr><td><strong>TERRITOIRES</strong></td></tr> <tr><td><input type="radio" name="terriprod" value="P" onClick="Javascript:alert('la valeur de terriprod...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
7
by: Rajesh S R | last post by:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/ Is it valid? I know that it has been discussed in comp.std.c. ...
17
by: Martin Wells | last post by:
When passing arguments to a VAL function, all integer types are promoted, and floats become doubles. Therefore, signed short will be promoted to signed int. Therefore I can't see any reason why...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.