C + + about how to get the maximum value of type int

Source: Internet
Author: User

Before there is a problem, because the minimum value when Minn initial assignment is not large enough, leading to have not been, card for a long time.

Then I assiduous to learn the following:

The maximum value of type int is 0x7fffffff,

 can calculate how much 0x7FFFFFFF is  
each hexadecimal number 4bit, so 8 bits 16 binary is 4 bytes, just an int integer (as if a byte is 8 bit)

f a binary code of 1111
7 binary code is 0111

in this way, the binary representation of the entire integer 0x7FFFFFFF is except that the first is 0 and the rest is 1
that is, this is the largest integer int (because the first bit is the sign bit, 0 means that he is a positive number)


So visual 0x seems to indicate that this is a hexadecimal number.
The corresponding minimum value can be expressed as 0x80000000 or int_min, one of the problems is that Int_max and Int_min are included in a header file called <climits>, and the header file is used as follows:
<climits> the symbol constants defined by the header file
Char_min minimum value of Char
Schar_max signed Char maximum value
Schar_min signed Char minimum value

Uchar_max unsigned char maximum value
Shrt_max Short Maximum value
Shrt_min Short Minimum value
Ushrt_max unsigned short max value
Int_max int Maximum Value
int_min int Minimum value
Uint_max unsigned int maximum value
uint_min unsigned int minimum value
Long_max Long Maximum value
Long_min Long Minimum value
Ulong_max unsigned long Maximum value
Flt_mant_dig the mantissa of type float
Flt_dig The least significant digits of the float type
Flt_min_10_exp minimum value of the negative exponent of the float type with all valid numbers (base 10)
Flt_max_10_exp maximum value of positive exponent of type float (base 10)
Flt_min a positive minimum value of float type with full precision
Flt_max float type Positive maximum value
Well, here has to feel the lack of knowledge of their own orz,,, about 0x80000000, in fact, is the number of negative storage means is the complement, check the relevant introduction recorded in the following:
A negative number in a computer is a complement to its complement = The original code negation +1

A binary representation is 10000000-01111111 (note: Highest bit representation symbol)
The highest bit is 1, the highest number is negative, and the maximum is 0 is positive.
If 7 The original code is 10000111 then take the inverse (the highest bit is compliant without taking the reverse) get 11111000
Plus a 11111001, so--7 's binary number is 11111001.
Again like-10 The original code is 10001010 to take the reverse 11110101 plus a 11110110
So--10 binary number is 11110110.
Binary number is every binary one only 0 and 12 digits No 2

C + + about how to get the maximum value of type int

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.