Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What is signed int and unsigned int?


Asked by Adelina Nunez on Dec 05, 2021 FAQ



An unsigned variable type of int can hold zero and positive numbers, and a signed int holds negative, zero and positive numbers. In 32-bit integers, an unsigned integer has a range of 0 to 2 32 -1 = 0 to 4,294,967,295 or about 4 billion.
In fact,
As the names imply, int is a signed integer type, and unsigned int is an unsigned integer type. That means that int is able to represent negative values, and unsigned int can represent only non-negative values. The C language imposes some requirements on the ranges of these types.
Likewise, int and unsigned int are two distinct integer types. (int can also be referred to as signed int, or just signed; unsigned int can also be referred to as unsigned .) As the names imply, int is a signed integer type, and unsigned int is an unsigned integer type.
Keeping this in consideration,
A signed integer can store the positive and negative value both but beside it unsigned integer can only store the positive value. The range of nonnegative values of a signed integer type is a sub-range of the corresponding unsigned integer type.
In respect to this,
Unsigned variables, such as unsigned integers, will only allow you to represent numbers in the positive. Unsigned and signed variables of the same type (such as int and byte) both have the same range (range of 65,536 and 256 numbers, respectively), but unsigned can represent a larger magnitude number than the corresponding signed variable.