In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: Okay, Here is my routine. I kind of combined everything that has been posted in this thread. I think it's pretty neat and clean... [code] '--------------------------------------------------------------------------- Bin16DEC: ' Use: Bin16DEC word ' -- Convert a 16bit binary variable into a decimal value. ' define BLANK as 00h for BCD nibbles ' define BLANK as 30h to directly output ASCII ' to a terminal or LCD. ' Original versions by Bean (Hitt Consulting) & Michael Chadwick & John Couture ' ' Setup ' temp VAR Byte ' wTemp VAR Word ' wDDivisor VAR Word ' ascDigit VAR Byte (5) IF __PARAMCNT = 1 THEN ' if parameter is a Byte or Word variable wTemp = __PARAM1 ELSE wTemp = __WPARAM12 ENDIF ' fill all locations with zeros PUT ascDigit(0), BLANK, BLANK, BLANK, BLANK, BLANK ' Loop for first 4 digits FOR temp = 0 TO 3 ' Get divisior for this digit LOOKUP temp, 10000, 1000, 100, 10, wDivisor ' Increase digit until value < divisor DO UNTIL wTemp < wDivisor INC ascDigit(temp) wTemp = wTemp - wDivisor LOOP NEXT ' Last digit is just units, so just add it ascDigit(4) = ascDigit(4) + wTemp_LSB RETURN [/code] Bean. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=138199#m138341 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)