not quite understanding the MATH function


Results 1 to 11 of 11

Threaded View

  1. #9
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    yea, >>2 is the same as dividing by 4, >>3 is the same as dividing by 8 etc... you can also multiply by shifting left (e.g. <<1 is the same as multiplying by 2)

    the line "time[chl] = (chnl1[chl] - 510) / -255" can of course be re-written as "time[chl] = (510 - chnl1[chl]) / 255". If you dont mind dividing by 256 instead it could also be written as "time[chl] = (510 - chnl1[chl])>>8" and would be much quicker to execute. However you must keep in mind that the result of this line is ALLWAYS going to be an integer even if the real matematical answer is 1.3 for example, the value stored in time[chl] will be 1

    the same thing applies to the lines with 1.5 in them. the variables cant not possibly be equal to 1.5. You seem to be trying to check if the variable time[lmt] is bigger than, less than or equal to 1.5. This is not possible since time[lmt] is of course an integer and can only have whole values. You may need to re-think how your program works if you are trying to use a range of numbers between 1 and 2.

    Perhaps you can post the equations/algorithms that you are trying to calculate and I may be able to work out what you are trying to do in your program.

    Just for your reference, a variable that has been declared as a byte has 256 possible values in the set [0,1,2,...,255]. A variable that has been declared as a word has 65536 possible vlaues in the set [0,1,2,...,65535]
    Last edited by Kamikaze47; - 17th January 2006 at 19:25.

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 04:01
  2. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 05:20
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 10:45
  5. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 15:05

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