Using an arduino uno what will be the result if you write co

Using an arduino uno, what will be the result if you write code to grab 2048 10 bit a/d samples into an integer variable array in the arduino uno then multiply each element by a scalar value of 25? Explain.

Solution

Nothing happens because 10 bit value multiplied by 25 corresponds to value that interger variable can handle

i.e.

max. value formed by 10 bit = 1024

max. value handled by integer variable = 16 bit = 32768

1024*25= 25600 < 32768.

Incase you wish to multiply 10 bit value by 50 then max. result will be 51200 > 32768

Under this situation INTEGER OVERFLOW condition occurs.

INTEGER OVERFLOW

An Integer Overflow is the condition that occurs when the result of an arithmetic operation, such as multiplication or addition, exceeds the maximum size of the integer type used to store it. When an integer overflow occurs, the interpreted value will appear to have “wrapped around” the maximum value and started again at the minimum value, similar to a clock that represents 13:00 by pointing at 1:00.

For example, an 8-bit signed integer on most common computer architectures has a maximum value of 127 and a minimum value of -128. If a programmer stores the value 127 in such a variable and adds 1 to it, the result should be 128. However, this value exceeds the maximum for this integer type, so the interpreted value will “wrap around” and become -128.

And incase you are woried about the ARRAY part of it then array is user defined datatype and it won\'t affect in integer\'s limit to stores the values.

Just visit integer reference page in help menu of anduino sketch.

Using an arduino uno, what will be the result if you write code to grab 2048 10 bit a/d samples into an integer variable array in the arduino uno then multiply

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site