'Bean (Hitt Consulting) 'Parallax forum http://forums.parallax.com/forums/default.aspx?f=7&m=138199 '--------------------------------------------------------------------------- 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 ' wDivisor 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