Shop OBEX P1 Docs P2 Docs Learn Events
Conversions — Parallax Forums

Conversions

whitelancerwhitelancer Posts: 23
edited 2006-08-01 18:55 in General Discussion
To anyone that can help,

I am trying to take a decimal number and turn it into a hexadecimal number that i can send to my servo controller to move the servo motors. The process needs to take a number (such as 300) and then convert it to binary from. Then 2 data bytes need to be created with Data 2 containing the lower 7 bits, and Data 1 containing the upper bits as descirbed in this link (http://www.pololu.com/products/pololu/0207/ssc03a_guide.pdf). I was hoping if there was a program already created for conversion purposes since I don't think the Javelin has it embedded or if anyone could help me out.

Thanks!

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-01 16:02
    Say your value is stored in value:
    int value = 300;
    then to convert into 2 7bit databytes:
    int data2 = value&0x7F; //data2 holds lower 7 bits
    int data1 = (value>>>7)&0x01; //data1 bit0 holds MSB

    regards peter
  • whitelancerwhitelancer Posts: 23
    edited 2006-08-01 18:48
    Im not sure how this works. If i changed the value to say 3000 dosn't that change the answer and the final answer needs to be in hexadecimal units. Let me know if I am missing something.

    Thanks!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-01 18:55
    I don't see any mention of hexnumbers in the manual.
    Only that all databytes must have bit7 cleared (pololu mode).

    Please give an example of your data and into what you
    would like it converted (in bytes).

    regards peter
Sign In or Register to comment.