Overflowing of Unsigned Int
unsigned
numbers can't overflow, but instead wrap around using the properties of modulo.
For instance, when unsigned int
is 32 bits, the result would be: (a * b) mod 2^32
.
As CharlesBailey pointed out, 253473829*13482018273
may use signed multiplication before being converted, and so you should be explicit about unsigned
before the multiplication:
unsigned int someint = 253473829U * 13482018273U;
Unsigned integer overflow, unlike its signed counterpart, exhibits well-defined behaviour.
Values basically "wrap" around. It's safe and commonly used for counting down, or hashing/mod functions.