| ??? 05/14/03 11:08 Read: times |
#45413 - RE: find the average of 12 numbers-best way? Responding to: ???'s previous message |
Matt:
Is this homework? Whatever.....the code you show seems to me to be far off the mark as a piece of code to compute the average of the 12 numbers. Given 12 numbers N1, N2, N3, ..... N12, the average computation would be: ![]() As you write code for a computation like this you have to take into account the range of values in the numbers that you are adding up. If it is bytes that you add, with a full range of values from 0 to 255 in each byte, then the maximum sum in the numerator of the formula can be 255 * 12 = 3060. As you can see it takes more than 8 bits to hold this value. Thus to perform the average you would have to sum the 12 numbers as a 16-bit wide sum. And obviously the division would be a 16-bit dividend as well. If you were to tell me that the maximum value that would be in any of the twelve number bytes would be 255/12 = 21 (rounded down to an integer) then the use of an 8-bit summing process for the numerator would be OK. --- It looks to me like you are trying to learn coding without actually trying to run it. If that is the case why don't you get an 8051 Simulator tool and step through the code you make to see how and why it does or does not work. Michael Karas |
| Topic | Author | Date |
| find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 | |
| RE: find the average of 12 numbers-best way? | 01/01/70 00:00 |




