Integer Math Tips


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    Bear with me, I am a beginner

    I have read the DIV32 entry from the manual, that's how I learned about DIV32 in the first place. It says it can divide a 31bit number by a 15bit number, that means I could make the numerator very large, but he problem is that since the value of Vout (the denominator) can be as low as 1, then the result would not fit into a WORD variable. Therefore the maximum value for the numerator has to be 65535, which is what I got in my example. (well 65535 is technically 1024*64, but you get the point)

    Vin = 1023 * 64
    temp = Div32 Vout

    Maybe you mean something I am not seeing, if so please let me know, I am new to this stuff.

    Also I am not sure what you mean about my measuring method? All I want is to compute the unknown resistance from a voltage divider. But that should be irrelevant, shouldn't it? I mean, the problem here is just an integer arithmetic one.

    I appreciate your help guys.
    Last edited by dream-; - 26th August 2010 at 17:34.

  2. #2
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Alain,

    I think I understand what you mean with the comment about the measurement range. Maybe I could just make two cases or simply make Vout have a range from say 3 to 1023. That way I could really scale up the numerator and still have a result within the bounds of a WORD.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's one of the best sites I know of for tips & tricks working with integer math on small systems: http://www.emesystems.com/BS2index.htm
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Thank you Bruce, that page has a wealth of information!

    There is even a section on my particular problem of division where the denominator is a variable.

    Let's see how they do it...

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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