Home » C#.Net

Difference between Int32 and UInt32 in C#

C# Int32 and UInt32 Differences: Here, we are going to learn about the differences between C# Int32 and C# UInt32 data types.
Submitted by IncludeHelp, on February 11, 2019

C# Int32 and C# UInt32

In C#, Int32 known as a signed integer of 4 bytes which can store both types of values including negative and positive between the ranges of -2147483648 to +2147483647.

UInt32 known as an unsigned integer of 4 bytes which can store only positive values between the ranges of 0 to 4294967295.

Differences between 'Int32' and 'UInt32'

Int32 UInt32
Int32 stands for signed integer. UInt32 stands for unsigned integer.
It's capacity to store the value is -2147483648 to +2147483647. It's capacity to store the value is 0 to 4294967295.
It can store negative and positive integers. It can store only positive integers.
It occupies 4-bytes space in the memory. It also occupies 4-bytes space in the memory.
Declaration syntax:
Int32 variable;
Declaration syntax:
UInt32 variable;

Example:

In this example, to explain the differences between Int32 and UInt32 in C#, we are printing their minimum and maximum values, we are also declaring two arrays – arr1 is a signed integer type and arr2 is an unsigned integer type. Initializing the arrays with corresponding negative and positive values based on their capacity.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //Int32 value range 
            Console.WriteLine("Int32 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", Int32.MinValue, Int32.MaxValue);

            //UInt32 value range 
            Console.WriteLine("UInt32 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", UInt32.MinValue, UInt32.MaxValue);

            //Int32 array
            Int32[] arr1 = { -2147483648, 0, 12320009, 2147480000, 2147483647 };
            Console.WriteLine("UInt32 array elements...");
            foreach (Int32 num in arr1)
            {
                Console.WriteLine(num);
            }
            Console.WriteLine();

            //UInt32 array
            UInt32[] arr2 = { 0, 100, 23000, 4294960000, 4294967295 };
            Console.WriteLine("UInt32 array elements...");
            foreach (UInt32 num in arr2)
            {
                Console.WriteLine(num);
            }

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

Int32 value capacity...
Min: -2147483648, Max: 2147483647

UInt32 value capacity...
Min: 0, Max: 4294967295

UInt32 array elements...
-2147483648
0
12320009
2147480000
2147483647

UInt32 array elements...
0
100
23000
4294960000
4294967295





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.