Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
hi people
i want to know what is the difference between int and uint both the data types are same
and can we replace uint with int
and Convert.ToUint32 to Convert.ToInt32??
Posted
Updated 12-Sep-18 11:00am
Comments
[no name] 1-Jul-14 8:50am    
No they are not the same. Is that what your research lead you to believe? An int is signed and a uint is unsigned.
[no name] 1-Jul-14 10:07am    
oh thank you i guess i should use uint as required

Refer - What is the difference between “int” and “uint” / “long” and “ulong”?[^].
Quote:
The limits for int (32 bit) are:
int: –2147483648 to 2147483647 
uint: 0 to 4294967295
Quote:
can we replace uint with int
Yes, if you don't have negative numbers to deal with.
 
Share this answer
 
v2
Comments
[no name] 1-Jul-14 10:07am    
thank you
i'll use uint
Sergey Alexandrovich Kryukov 1-Jul-14 11:11am    
5ed.
—SA
Thanks Sergey. :)
1. uint equivalent with Uint32 - means unsigned integer and can have only positive values;

2. int is equivalent with Int32 -and is a normal integer type can can have also negative values

3. You can convert from one type to other if both are positive values and in the case from uint to int if the value is not bigger then Maximum value for Int32.
 
Share this answer
 
Comments
[no name] 1-Jul-14 10:06am    
thank you too
Raul Iloc 2-Jul-14 1:03am    
Welcome!
Sergey Alexandrovich Kryukov 1-Jul-14 11:13am    
One note: "equivalent" means that uint and int are C# aliases for System.UInt32 (note fixed capitalization and full type name) and System.Int32. Voted 4.
—SA
http://stackoverflow.com/questions/3724242/what-is-the-difference-between-int-and-uint-long-and-ulong[^]


The limits for int (32 bit) are:

C++
int: –2147483648 to 2147483647 

C++
uint: 0 to 4294967295 


And for long (64 bit):

C++
long: -9223372036854775808 to 9223372036854775807

C++
ulong: 0 to 18446744073709551615
 
Share this answer
 
Comments
[no name] 1-Jul-14 10:06am    
thank you too
Alternatively, in PLC programs, sometimes SINT is a signed integer data type.
 
Share this answer
 
Comments
Richard Deeming 13-Sep-18 15:07pm    
Absolutely nothing to do with the question, which already has several perfectly good answers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900