RE: [Dev-C++] bit extraction problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-08-17 12:44:03
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Dawood Vora > Sent: Sunday, August 17, 2003 10:07 AM > To: Dev C++ > Subject: [Dev-C++] bit extraction problem > > > bit extraction problem > > Below is a program to extract the layout of the bits from an integer. > It works fine, if the input number is within the range of > long type of int. > It is suppose to give me a message, if the input number is > either greater > than the max limits of long or lower than the min limits of > long. But it > does not. Apparently the offending line is : "cin>>x;" If x > is not able > to accommodate any input number it simply stores the number 2 > as per my > system. Does anybody know, how to solve this problem. Read the number as a string so as to be sure that it fits however large the "value" is. Then make some trick to see if it is within numeric_limits<long>::max(), numeric_limits<long>::min() (defined in <limits> which are the equivalent of LONG_MIN and LONG_MAX defined in <climits>). Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |