Help!! Integer Math?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    As I understand it...

    Subtracting adval-adval1 gives you positive Celcius.

    Therefore adval1-adval would give you negative Celcius. The math is the same. Conversion to Farenheit is more tricky. But stop and think before you go any further...

    If you Reference everything to a single numeric value... say a value of 0 in a BYTE (or WORD) variable, equals the lowest Temperature you are likely to encounter (example -100C). Do your (positive or negative math) so you have ONE positive going linear scale, from that lowest Temperature reference point. Then it's a simple matter of calculating C or F using that one variable.
    Example.

    Say a count of ONE of (adval-adval1) equals 1C positive then.

    So...

    If adval>adval1 then
    TEMP=100+(adval-adval1)
    else
    TEMP=100-(adval1-adval)
    endif

    Now we have a single variable TEMP which holds a linear representation of our whole Temperature range. Now from this variable we can calculate C or F easily.

    In our above example a count of 100 is 0C. Anything over 100 is positive, and anything lower than 100 is negative.

    If TEMP<100 then
    TEMPB=100-TEMP
    LCDOut "-",#TEMPB," C"
    else
    TEMPB=TEMP-100
    LCDOut #TEMPB, "C"
    endif

  2. #2
    Join Date
    Mar 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    I have been out of the office today! I was working on this late last night and come up with the following:

    if adval > adval1 then
    celsius = adval - adval1
    farenheit = (celsius * 18)/10
    farenheit = farenheit + 32
    status = 0
    else
    celsius = adval1 - adval
    farenheit = (celsius * 9)/5
    farenheit = 32 - farenheit
    status = 1
    endif

    if (status = 1) & (celsius > 32) then
    sign = "-"
    else
    sign = "+"
    endif

    I will try your code tonight!

    Thanks for your help,

    Scott

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 03:01
  2. Replies: 5
    Last Post: - 28th May 2008, 10:20
  3. Pulsin Math question
    By ruijc in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2008, 16:15
  4. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  5. Help!! Integer Math?
    By scottl in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th June 2006, 13:47

Members who have read this thread : 0

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