Hi 8051 Gurus, The question i have is general C question and not specific to any chip. I have two variables of long type, which is the maximum storage size supported. I want to know whether it will cause an overflow while multiplying these two variables or not. I dont want to use any assembly code as i said this is not specific to chip. E.g.
long a, b, c; c = a * b;
Anyone can help me. Also i donw want to use multibyte maths which will be again processor specific...!!
Thanks in Advance...!!
One approach would be to determine the number of significant bits of each number. The result will have a number of signifcant bits equal to the sum of significant bits of the two input values. If the number of significant bits of the result exceeds that of the length of the datatype, an overflow is possible (but not guaranteed, since 10b * 10b = 100b (only three bits)).