User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
134
Alternatively, when using integer variables multiply the dividend by 10, 100, 1000 etc. before
dividing. The result will gain extra digits of precision but must be interpreted correctly. Using the
previous example we can gain three digits of precision as follows. This is known as xed point
division:
temp = dividend * 1000 ;dividend is now 76000
result = temp/7
The example sets “result” to a value of 10857.
High Multiplication (**)
If two long variables or constants are multiplied, the result may exceed 32 bits. Normally, the
multiply function will return the least signicant (lowest) 32 bits. The ** function will, instead,
return the most signicant 32 bits.
time = 80000 ** 80000 ; result returns high 32 bits
The value of time would be equal to 0x1 which is the high 32 bits of the result 6,400,000,000.
Fractional Multiplication (*/)
Fractional multiplication will multiply a number with a fractional part. The multiplier must be a
long value which is handled by a special method. The high 16 bits are the integer portion of the
multiplier, the low 16 bits are the fractional part (expressed as a fraction of 65536). The result
will be an integer with any fractional remainder discarded (not rounded).
Let us say we want to multiply the number 346 x 2.5. The multiplier must be constructed as
follows. The high 16 bits will have a value of 2. We can do this with:
mult.highword = 2
The low 16 bits will have a value that is half of 65535 or 32782 so:
mult.lowword = 32782
Then we do the fractional multiply:
a = 346 */ mult
The example will give “a” the value 865. A similar procedure will let you multiply by any fraction
by expressing that fraction with a denominator of 65535 as closely as possible.
Notice that half of 65535 is actually 32782.5; a number we can not enter as the fractional part.
This means that multiplication by exactly half is not possible. However, the difference is so small
that it has no effect on the actual outcome of the integer result.