NSInteger Types

I would like to know what is the differecnce between Integer 16, Integer 32 and Integer 64, as well as the difference between an integer sign and an unsigned integer (NSInteger and NSUInteger)

+5
source share
4 answers

I'm not sure what types you mean by "Integer 16", "Integer 32", and "Integer 64", but usually these numbers refer to the size in bits of an integer type.

The difference between an integer, signed and unsigned, is the range of values ​​that it can represent. For example, a signed 16-bit integer with two additions can represent numbers from -32.768 to 32.767. An unsigned 16-bit integer can represent values ​​from 0 to 65535.

For most computers used today, an integer with a sign of width n can represent the values ​​[-2 n-1 2 n-1 ) and an unsigned integer with a width of n can represent the values ​​[0.2 n ).

+11
source

NSInteger NSUInteger Apple. , - . 32- NSInteger typedef'd int, 64- - typedef'd. NSUInteger typedef'd unsigned int 32- unsigned long 64-. [-2 ^ (n-1), 2 ^ (n-1)], n - , [0, 2 ^ n].

, NSInteger NSUInteger, . , , , . , stdint.h(.. Uint8_t, uint16_t, uint32_t ..).

+5

vs -

, . , /, int .

, , int. .

+1
source

Take a look at Basic Data Types . NInteger and NSUInteger and typedef for int and unsigned int.

From Wikipedia

When calculating the signed representation number, negative numbers in the binary number of the system must be encoded

which means you should usually use a bit to encode a character, thereby reducing the range of the number you can imagine.

+1
source

All Articles