Shop OBEX P1 Docs P2 Docs Learn Events
hexadecimal & MMC — Parallax Forums

hexadecimal & MMC

JavalinJavalin Posts: 892
edited 2004-09-11 11:40 in General Discussion
Hi,

Trying to use the Javalin to replace a BS2.· I am having issues with controling the Motor Mind C (MMC).

Does anybody know what the Java replacements for the PBASIC conversion functions like DEC, HEX, etc are?

I need to use these to convert and send a decimal number as a hexidecimal string via RS232/TTL serial link

Thanks!

James

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-09-11 11:35
    Hi,

    Get application note AN012 from here

    http://www.parallax.com/javelin/applications.asp



    The format class offers 3 methods to print integer values with base

    2, 8, 10 or 16.

    printf() prints to system.out

    sprintf() prints to character array

    bprintf() appends to a character array.

    To print an integer value as hex use

    int value = 12; //example value

    char[noparse]/noparse hexbuf = new char[noparse][[/noparse]5]; //to hold hex string

    hexbuf[noparse][[/noparse]5]=0; //make hexbuf an asciiz string (optional)

    Format.sprintf(hexbuf,"%04x",value); //hexbuf holds '0','0','0','C',0

    for (int i=0; i<4; i++) txUart.sendByte(hexbuf[noparse][[/noparse]i]); //transmit hexvalue

    Read the application text how to use format specifiers.

    There are specifiers for binary,oxtal,decimal,hexadecimal and unsigned.



    regards peter
  • JavalinJavalin Posts: 892
    edited 2004-09-11 11:40
    you absolute star!

    New it must be possible!
Sign In or Register to comment.