Shop OBEX P1 Docs P2 Docs Learn Events
Mulplication with fractions .. stuck on this — Parallax Forums

Mulplication with fractions .. stuck on this

dufflingduffling Posts: 73
edited 2005-03-09 08:24 in BASIC Stamp
Im developing a MIDI controller for my digital mixer .. and to send one particular type of sysex requires both division and multiplication of a integer by 12.8

is there are work around i can use to both divide and multiply a value such as 76 by 12.8 ?


the value has a range of 1 to about 127 , and has to be divided by 12.8· basically

any help much app..

Comments

  • gordianknotgordianknot Posts: 12
    edited 2005-03-09 03:28
    I hope this helps -
    - Try multiplying 76 by the reciprocal of 12.8 which would be 1/12.8 : The answer is 5.9 the same as if you divided 76 by 12.8 (=5.9)
  • KenMKenM Posts: 657
    edited 2005-03-09 03:30
    And be sure to visit this site....the guru of Stamp Math

    http://www.emesystems.com/BS2index.htm
  • dufflingduffling Posts: 73
    edited 2005-03-09 03:44
    thanks for the reply , any chance u can give me a snip of what this would look like in 2.5 code?
    ·
  • kb2hapkb2hap Posts: 218
    edited 2005-03-09 04:14
    2 things you can do
    1-get a floating point math coprocessor
    2-do a lot of fiddling with numbers
    its hard to tell you exactly what to do or how to code it because I'm sure mult and div 76 by 12.8 aren't the only numbers you are using.

    but for example you could figure that you could mult 76 by 128(12.8*10) right that gives you 9728
    now depending on what you want to do with that number thats were you really have to play are you doing a serout/shiftout?
    then you would (maybe) have to send
    math:
    highnum=9728/10
    lownum=dig0 9728
    Send:
    serout dpin,baud,(dec3 highnum,".",dec1 lownum)
    this is kinda general but it gives you an idea of how you may have to play around with the numbers to get what you looking for.
    it really all depend on the final outcome your looking for .

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DTQ
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-03-09 06:14
    ' {$PBASIC 2.5}
      ' assuming you need a decimal output with good precision:
      x VAR byte    ' range 1 to 127
      y VAR word   ' x * 12.8, range 12.8 to 1625.6   
      z VAR word   ' x/12.8, range 0.078 to 9.922
      DO
        DEBUG "enter x (1--127): "
        DEBUGIN dec x
        y = x */ 32768     ' multiply: 32768/256= 12.8 * 10
        z = x */ 20000    ' multiply: 20000/256=1/12.8 * 1000
        DEBUG CR, DEC x, TAB, DEC y/10, "." ,DEC1 y, TAB, DEC z/1000, ".", DEC3 z
      LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dufflingduffling Posts: 73
    edited 2005-03-09 07:37
    great! .. thanks for the replys .. i understand the logic now .. thanks again!
  • dufflingduffling Posts: 73
    edited 2005-03-09 07:53
    one other question however...

    I actually need to divide numbers as high as 2400 by 12.8 ........ the above example will only allow me to divide small integers..

    thanks again !
  • KenMKenM Posts: 657
    edited 2005-03-09 07:56
    Did you visit emesystems.com?·It is explained there with code examples.
  • dufflingduffling Posts: 73
    edited 2005-03-09 08:24
    Checking it now .. thanks for the help.
Sign In or Register to comment.