Int range and conventions

Source: Internet
Author: User

A question arises:
In 32-bit machines, the int range is-32768 ~ 32767
Instead of-32767 ~ 32767
-How can I get 32768?

========================================================== ============
Message Group: Group/record ()
========================================================== ============
Message Type: Chat History
========================================================== ============

10:01:48 new to kindergarten (404082727)
[: L] I was wrong last night and nobody asked me

10:02:39 beef noodle ()
Wrong?

10:03:55 new to kindergarten (404082727)
The reverse code is not obtained in that way. The complement code calculation is naturally wrong, and the conclusion is not mentioned.
 

10:04:34 new to kindergarten (404082727)
The question you asked is also a bit problematic. I am misled by these young people.

10:06:02 new to kindergarten (404082727)
However, I was bullied only when I had a poor foundation. [: <]

10:06:05 beef noodle ()
(21:43:05) New to kindergarten (404082727)
-32768 original code 1100 0000 0000
-32768 reverse code 0011 1111 1111
-32768 complement 0100 0000 0000 0000

Is that true?

10:06:18 new to kindergarten (404082727)
Well

10:07:06 hellosam ()
-32768 supplemental code 1000 0000 0000 0000?

10:07:17 beef noodle ()
I read the materials today

10:08:02 new to kindergarten (404082727)
I checked that the int value range is-32768 ~ 32767

10:08:16 new to kindergarten (404082727)
So you misled us.

10:08:35 new to kindergarten (404082727)
I think it's also a collapse of the lake

10:08:57 new to kindergarten (404082727)
Sorry.

10:09:31 beef noodle (215631428)
I asked:
In 32-bit machines, the int range is-32768 ~ 32767
Instead of-32767 ~ 32767
-How can I get 32768?
 

10:09:45 hellosam ()
It is actually-0

10:09:54 hellosam ()
But-0 is meaningless.

10:10:05 hellosam ()
It indicates-32768.

10:10:28 hellosam (0)
The complement range is one more than the original code.

10:10:42 hellosam ()
It is moved from-0.

10:18:09 new to kindergarten (404082727)
Minimum number of original codes 1111 1111 1111 1111
Reversed code 1000 0000 0000 0000
Code 1000 0000 0000 0001
This number should be:
Then the minimum number of complement codes is:
1000 0000 0000 0000

10:21:39 new to kindergarten (404082727)
I also want to see it.

10:24:11 new to kindergarten (404082727)
This is a strange number!

10:24:27 new to kindergarten (404082727)
I don't know how to calculate it-2 ^ 15
 

10:28:00 new to kindergarten (404082727)
32768 ~ 32767 (not 32768) is the range of a 16-bit Compiler (such as Turbo c2.0.

10:29:04 new to kindergarten (404082727)
It has little to do with the machine bit (on the surface, right?). It is related to compiler implementation,

10:29:28 hellosam (57532790)
Well, now it's all 32-bit machines.

10:30:48 new to kindergarten (404082727)
In C/C ++, the header file limit. h/climit. H has an integer range defined.

10:31:21 new to kindergarten (404082727)
Open it if you are interested,

10:31:52 new to kindergarten (404082727)
You can also use sizeof to see

10:32:08 beef noodle (215631428)
Oh, look

10:32:15 hellosam ()
It can be viewed as several bytes.

10:32:53 new to kindergarten (404082727)
When several bytes are set, the range is also set to pull.

10:33:42 new to kindergarten (404082727)
Min_int is the smallest number macro!
 

Conclusion:

10:34:55 new to kindergarten (404082727)
R & k c does not define the exact length and accuracy of the numeric type.It is only stipulated that short cannot be longer than integer, and integer cannot be longer than long. Therefore, it depends on different platforms and different C compilers.

11:02:44 new to kindergarten (404082727)
Supplement:The ansi c standard specifies the minimum value range for each integer type (but does not specify the encoding scheme they must use), and requires all C language implementations to be implemented in limits. in the H header file, macros such as int_min and int_max are used to specify the actual value range of integer data, in addition, these actual value ranges must not be smaller than the standard minimum value range (that is, each implementation is required in limits. the absolute value of the macro defined in H is not smaller than the absolute value of the same-name macro defined in C, and the symbols must be consistent ). The standard int_min is-(2 ^ 15-1) and int_max is (2 ^ 15-1). In other words, the standard ensures that int data can represent at least all integers in a symmetric interval (2 ^ 15-1) to (2 ^ 15-1). ThereforeProgramYou can use int variables to store any integer in the above range with confidence. But at the same time, please note that using int variables to express the number beyond the above range is a matter that is not protected by law (the standard is the programmer's Law, therefore, it should not be assumed that-32768 (I .e.-2 ^ 15) must be expressed in the int type, although it is indeed in the twos-complement notation Method) within the value range of the 16-bit integer.

11:16:14 new to kindergarten (404082727)
Note that the final interpretation of machine-related types is determined by the compiler.Therefore, the length of an integer is determined by your compiler rather than the machine. TC indicates that Int Is int16 and long is int32.

Others:

11:20:23 new to kindergarten (404082727)
When int_min (32-bit int value is 0x80000000, that is,-2147483648), negative retrieval of it will overflow, because a 32-bit int can represent the maximum positive number of int_max (0x7fffffff, that is, 2147483647 ). In fact, int_min has nothing to do with the negative value (0x80000000 according to the Supplementary Code or 0x80000000 ). Because the return value of the function declaration is also int,

11:21:05 new to kindergarten (404082727)
The simple solution is to use a variable of the unsigned int type to receive the return value. Because the value range of the 32-bit unsigned int is 0 to 4294967295 (0 xffffffff) and 2147483648 falls in this range, the unsigned int variable can be used to correctly express the absolute value of int_min.

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.