Shop OBEX P1 Docs P2 Docs Learn Events
graphing math to hex need help — Parallax Forums

graphing math to hex need help

science_geekscience_geek Posts: 247
edited 2008-11-04 03:01 in Propeller 1
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

  • evanhevanh Posts: 15,545
    edited 2008-11-03 21:38
    I'm guessing you want to convert two floating point numbers to two integers.

    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.
  • evanhevanh Posts: 15,545
    edited 2008-11-03 22:32
    Ok, looking up the uoled-32038-pmd3t, I note it uses RS232 signalling. So, all you need after converting the floats is to transmit the data with one of the RS232 drivers. The original workhorse being Chip's Full Duplex Serial.

    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.
  • science_geekscience_geek Posts: 247
    edited 2008-11-04 00:06
    not to integers, i need to convert the hex equivelent of a decimal integer from a 4 digit hex into 2 seperate hex digit, like this

    128dec = 80 which is technically 0080

    so take the 0080 turn it into 00· 80

    and send 00(msb) and then 80(lsb)
  • VIRANDVIRAND Posts: 656
    edited 2008-11-04 00:29
    In Spin:

    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: idea.gif

    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
  • AribaAriba Posts: 2,687
    edited 2008-11-04 01:03
    if the display needs single hex numbers as ASCII bytes, then you can just use the hex() methode of FullDuplexSerial:
    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
  • Marc GebauerMarc Gebauer Posts: 60
    edited 2008-11-04 02:38
    This worked for me when I had to convert decimal to hex so that 0-9 units were stored in the $00-$09 range and 1 to 9 tens were stored in the $10 to $90 range.

    BCD := decimal + 6 * (decimal/10) <-- not a floating equation

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (Marc Gebauer) : 11/4/2008 11:18:58 PM GMT
  • science_geekscience_geek Posts: 247
    edited 2008-11-04 03:01
    OK,· i figured it out, i just wrote a simple if command since the number to graph technically can't exceed 320 without starting over, so if the number is greater than 255, the most significant bit is $01, otherwise its $00
Sign In or Register to comment.