By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

How to define the range of integer variable?

P: 3
We know that in 16bit compiler integer variable have 2bytes(16 bits).First MSB for sign and other 15bits for value.By converting this 15bit to value we can get only (-16384 to 16383).Then how can we get the range (-32768 to 32767)??.....please help me to deal with this.
Dec 12 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 1,059
your math was wrong

the output you got is equivalent to
pow(2,14)

try the mathe
pow(2,15)

you will get the answer for sure
Dec 12 '10 #2

Expert 100+
P: 2,396
The range of values that fit into the various types is implementation dependent. The Standard requires each implementation to explicitly specify its integer ranges with the macros of header file limits.h. (Floating point ranges are specified in float.h.)

The Standard mandates a certain minimum range for each data type, but each implementation is free to make the ranges larger. These minimum ranges are described at the limits.h link.

"We know that in 16bit compiler integer variable have 2bytes(16 bits).First MSB for sign and other 15bits for value"
Do not assume any particular encoding scheme. How negative numbers are encoded and whether there is a sign bit are implementation dependent. Your code will be nonportable if you try to make use of special knowledge like that.
Dec 12 '10 #3

Post your reply

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