What is the difference between int and unsigned int?

Recommended Answers

All 2 Replies

An int can store negative numbers that usually range from about -2.1 billion to about 2.1 billion.

An unsigned int can only store positive numbers that usually range from 0 to about 4.2 billion.

In a 32-bit system, an int is typically 32-bits long with the first bit being the "sign bit". If the sign bit is "set", the number is considered negative. If you have an unsigned, the "sign bit" is ignored and is just considered another bit in the number.

sign bit
|
V
0000 0000 0000 0000 0000 0000 0000 0000  //this always represents zero (0)
|
V
1111 1111 1111 1111 1111 1111 1111 1111  //on most systems, this represents an int with a value of -1
X

1111 1111 1111 1111 1111 1111 1111 1111  //in an unsigned int, this represents 4,294,967,296 (about 4.2 billion)

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.