BCD to decimal

Previous topic - Next topic

Gary

Not sure if anyone still uses Binary Coded Decimal but I needed to write a BCD to Decimal conversion for my project and thought I would share the code with anyone that might need it

Code (glbasic) Select
FUNCTION bcdbin32:inval

LOCAL weight_lut[]
LOCAL weight, retval, i
DIMDATA weight_lut[], 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000

retval = 0

FOR i=0 TO 7
weight = weight_lut[i]
WHILE (bAND(inval,15))
retval = retval + weight
inval = inval - 1
WEND
inval = ASR(inval, 4)
NEXT

RETURN retval

ENDFUNCTION


Now I fully expect someone to point out there is a built in function that I have missed lol

Hope its useful for someone

Gary