PDA

View Full Version : Mulplication with fractions .. stuck on this

duffling
03-09-2005, 10:09 AM
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..

gordianknot
03-09-2005, 10:28 AM
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)

KenM
03-09-2005, 10:30 AM
And be sure to visit this site....the guru of Stamp Math

http://www.emesystems.com/BS2index.htm

duffling
03-09-2005, 10:44 AM
thanks for the reply , any chance u can give me a snip of what this would look like in 2.5 code?
·

kb2hap
03-09-2005, 11:14 AM
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 Allen
03-09-2005, 01:14 PM
' {\$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 (http://www.emesystems.com)

duffling
03-09-2005, 02:37 PM
great! .. thanks for the replys .. i understand the logic now .. thanks again!

duffling
03-09-2005, 02:53 PM
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 !

KenM
03-09-2005, 02:56 PM
Did you visit emesystems.com?·It is explained there with code examples.

duffling
03-09-2005, 03:24 PM
Checking it now .. thanks for the help.