Select Page

There are 8 basic integer types in C#. The names and ranges af these types are an industry standard, so they should also be valid in most other languages.

>

>

>

>

>

>

>

>

 Keyword Range bits byte 0 to 255 8 sbyte -128 to 127 8 ushort 0 to 65536 16 short -32768 to 32767 16 int -2,147,483,648 to 2,147,483,647 32 uint 0 to 4,294,967,295 32 long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 64 ulong 0 to 18,446,744,073,709,551,615 64

On first glance you may find these numbers odd, but this is due to the fact that computers represent these numbers using binary and hexadecimal numbers. In these number systems they are nice round numbers.

### Signed/Unsigned

All the integer types come in pairs. One signed and one unsigned. All the unsigned types go from 0 to 2^x – 1, where x is the number of bits in the type (the “width” of the type).
The signed types have one more negative number than positive ones. This may seem strange, but this is basically (slightly simplified) because zero is treated as a positive number, and so it all adds up in the end…

### Quick and dirty range check

There is a very simple way of telling an approximate range of any integer. It just so happens that 2^10 is almost exactly 1000. 1024 to be exact.
This means that for every 10 bits in an integer, you can multiply the range by 1000. So 20 bits for instance would give an approximate range of 1000*1000, or 1,000,000, and 32 bits would give 1000*1000*1000*4 (the 4 is for the last 2 bits…) or 4,000,000,000.
As you can see in the table above, it is only an approximation since the exact number is 4,294,967,295, but for most purposes it is good enough.