// Division Operator


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default // Division Operator

    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?

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: // Division Operator

    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.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: // Division Operator

    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.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: // Division Operator

    How about

    DEC2 (Value//100)
    Charles Linquist

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: // Division Operator

    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.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts