What will the unsigned int
contain when I overflow it? To be specific, I want to do a multiplication with two unsigned int
s: what will be in the unsigned int
after the multiplication is finished?
unsigned int someint = 253473829*13482018273;
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;