eli5: Type casting

613 views

casting of larger variable to smaller variable results in the modulo of larger variable by the range of smaller variable.

I mean seriously explain it like I’m 5

In: Other

2 Answers

Anonymous 0 Comments

Lets forget binary and all that for first. Imagine you have two datatypes, one is an 8 digit decimal number the other is a 4 digit decimal number.

If you cast 12345678 into the 4 digit type it will just forget the first 4 digits. So the result is 5678.

That is the mathematical operation “modulo by the range of the 4 digit number”. So in this case Modulo 10000 because thats how many numbers a 4 digit decimal number can represent.

Modulo means “divide with remainder and return only the remainder”, so basically the part of the number that can’t be divided by 10000.

With binary exactly the same happens.

You are viewing 1 out of 2 answers, click here to view all answers.