Let's say I have the following code:

byte a; //a number between 0 and 100

byte b;

byte c1,c2;

c1=a*b/100;

c2=byte(word(a)*word(b)/100);

Because a is constrained to 0,100, the value of c will between 0 and 255, so it fits in a byte.

What is the proper way to calculate c=a*b/100;

Is it the possibility c1? If I remember correctly, multiplications are executed before divisions in C, so we have c1=(a*b)/100, but here, even though c1 holds in a byte, (a*b) can exceed this limit (before the result is divided by 100), so should I explicitly cast a and b to words (what I did for c2) before doing the multiplication?

Recasting to byte is probably not useful, but is it necessary to cast a and b to words so that the temporary results a*b doesn't cause overflow?

Thanks!