max value of integer
In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int
can be 16 bit wide, though usually it is 32 bit.
The only requirement is that short int
<= int
<= long int
by size. Also, there is a recommendation that int
should represent the native capacity of the processor.
All types are signed. The unsigned
modifier allows you to use the highest bit as part of the value (otherwise it is reserved for the sign bit).
Here's a short table of the possible values for the possible data types:
width minimum maximumsigned 8 bit -128 +127signed 16 bit -32 768 +32 767signed 32 bit -2 147 483 648 +2 147 483 647signed 64 bit -9 223 372 036 854 775 808 +9 223 372 036 854 775 807unsigned 8 bit 0 +255unsigned 16 bit 0 +65 535unsigned 32 bit 0 +4 294 967 295unsigned 64 bit 0 +18 446 744 073 709 551 615
In Java, the Java Language Specification determines the representation of the data types.
The order is: byte
8 bits, short
16 bits, int
32 bits, long
64 bits. All of these types are signed, there are no unsigned versions. However, bit manipulations treat the numbers as they were unsigned (that is, handling all bits correctly).
The character data type char
is 16 bits wide, unsigned, and holds characters using UTF-16 encoding (however, it is possible to assign a char
an arbitrary unsigned 16 bit integer that represents an invalid character codepoint)
width minimum maximumSIGNEDbyte: 8 bit -128 +127short: 16 bit -32 768 +32 767int: 32 bit -2 147 483 648 +2 147 483 647long: 64 bit -9 223 372 036 854 775 808 +9 223 372 036 854 775 807UNSIGNEDchar 16 bit 0 +65 535