graphing math to hex need help
im working on a program that can display a graph of a parabola to get it working i decided to start out with a certain equation (y = a(x - h)2 + k, where h = 120, and k = - 160) im using a uoled-32038-pmd3t display from 4d systems so the h and k are set at the center of the display, i have it using the put pixel at (x,y) command and that is where i run into problems. due to the size of the display i need to send the y bit in Y(msb:lsb)(most significant bit)[noparse]:([/noparse]least significant bit) form, but im only dealing with one y value in my equation and i need to split it to the msb:lsb form which is in hex, so i was wondering if there was an easy way to convert a decimal value to hex in the form that i could send Msb first then the lsb
Comments
Hmm, looking at the floating point object it doesn't look like that's a provided function. Extracting it by hand will take some reading. Converting via a string would work but that seems messy to me.
Good question.
Actually, the datastream is prolly string based anyway. The float to string routines in the floating point object will be perfect. Hopefully, you can forget the integer part.
128dec = 80 which is technically 0080
so take the 0080 turn it into 00· 80
and send 00(msb) and then 80(lsb)
a :=128 'decimal
a := $0080 'or hex instead if you want
msb := a/$100 'high byte
lsb := a//$100 'low byte using mod , could also use instead lsb := a & $FF
other ways:
since a is WORD, you could get msb and lsb out of it using something like BYTE[noparse][[/noparse]a] and BYTE[noparse][[/noparse]a+1] , i think.
in floating point, divide a by 256 to get msb on one side of the decimal point,
and then round down msb to integer if you can.
then lsb would be a - (msb * 256). I'm not familiar with the float object.
Post Edited (VIRAND) : 11/4/2008 12:41:57 AM GMT
OBJ
ser : "FullDuplexSerial"
PUB
...
ser.hex(y, 4)
...
if not, then your problem has nothing to do with hex. Then you have perhaps to send 2 bytes (MSB,LSB):
ser.tx(y>>8)
ser.tx(y & $FF)
Andy
BCD := decimal + 6 * (decimal/10) <-- not a floating equation
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Marc Gebauer) : 11/4/2008 11:18:58 PM GMT