PDA

View Full Version : // Division Operator



Dick Ivers
- 8th September 2011, 23:08
PIC is part 12F1822. I'm not getting the correct division remainder from the // operator. When the remainder contains a leading zero the result omits the zero. For example:
If value = 802 the remainder reported from a "value//100" operation is incorrectly reported as 2.
If value = 812 the remainder is correctly reported as 12.
Any ideas?

cncmachineguy
- 8th September 2011, 23:31
I don't mean to sound like a smart A$$, but 2 does equal 2, so its not incorrect. Just that you want a leading zero? I am afraid you will need to do that part with software to add the extra zero.

Dick Ivers
- 9th September 2011, 00:34
I probably shouldn't have said the result was incorrect ... it was just not what I was expecting. The following example does the job:
value = 802
D0 = value DIG 0
D1 = value DIG 1
Therefore, the remainder after the 8 is reported as 02.

Charles Linquis
- 9th September 2011, 03:29
How about

DEC2 (Value//100)

Dick Ivers
- 9th September 2011, 14:27
Charles, I don't think dec2 will work.

I started using the //division operator naively expecting that the remainder result would be the same as we get on our decimal calculators. Wrong, //division yields the modulus remainder. This is what we got when we were learning long division back in the 4th grade. It is not the same as decimal remainder.

The DIG fix described above works fine. There may be other approaches.