Tuesday, 3 October 2017

What is Difference Among int , int16 , int 32 and int64

What is Difference Among int , int16 , int 32 and int64

In the learning phase developer are not much aware of the difference between primitive, FCL (framework class library), reference, and value types.It may cause of many bugs and performance issue in the code.In this article, I would like to present the different behavior of integer type.


  • Each type of integer has a different range of storage capacity

   Type      Capacity

   Int16 -- (-32,768 to +32,767)

   Int32 -- (-2,147,483,648 to +2,147,483,647)

   Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807)
  • int and Int32 are indeed synonymous; int will be a little more familiar looking, Int32 makes the 32-bitness more explicit to those reading your code. I would be inclined to use int where I just need 'an integer'.

  • The only real difference here is the size. All of the int types here are signed integer values which have varying sizes
    • Int16: 2 bytes
    • Int32 and int: 4 bytes
    • Int64 : 8 bytes
According to Jeffrey Richter(one of the contributors of .NET framework development)'s book 'CLR via C#':
int is a primitive type allowed by the C# compiler, whereas Int32 is the Framework Class Library type (available across languages that abide by CLS). In fact, int translates to Int32 during compilation.
int
It is a primitive data type defined in C#.
It is mapped to Int32 of FCL type.
It is a value type and represent System.Int32 struct.
It is signed and takes 32 bits.
It has minimum -2147483648 and maximum +2147483647 value.
Int16
It is a FCL type.
In C#, short is mapped to Int16.
It is a value type and represent System.Int16 struct.
It is signed and takes 16 bits.
It has minimum -32768 and maximum +32767 value.
Int 64
 It is a value type.
Represent System.Int64 struct.
In c#, long is mapped to Int64.
It is a FCL type.
It is signed and takes 64 bits.
Minimum capacity –9,223,372,036,854,775,808 and Maximum capacity+9,223,372,036,854,775,807.

Int32

It is a FCL type.In C#, int is mapped to Int32.It is a value type and represent System.Int32 struct.It is signed and takes 32 bits.It has minimum -2147483648 and maximum +2147483647 capacity.

Note

  1. A number of developers think that int represents a 32-bit integer when the application is running on a 32-bit OS and it represents a 64-bit integer when the application is running on a 64-bit OS. This is absolutely wrong.
  2. In C# int is a primitive data type and it always mapped to System.Int32 whether the OS is 32-bit or 64-bit.

2 comments:

  1. sir is there also any file like system.int64 or system.int16??
    and what is fcl type?

    ReplyDelete
  2. System is a namespace and where we have int16 ,int32 and int64 is defined as struct .if you are not using "using System" in your c# program then you have to use System.int16 instead of int16
    FCl is Framework Class Library which include property ,class ,interfaces and datatypes ,to provide access to System Functionality

    ReplyDelete