hexadecimal & MMC
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
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
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
New it must be possible!