Geez, yours is much simpler than the one I eventually came up with...
Here's what I had:
PARAMETER num && number to convert to bits
i = 2 && i is the power to which we're multiplying (bitwise rules)
lcstring = '' && to store the 1's and 0's
lnbits = 8 && loop is dynamic, lnbits is for padding empty spaces
DO WHILE .T.
IF num <= 0 && if <0 we can exit
IF EMPTY(lcstring) && if it started at 0, store 0 to lcstring lcstring = '0'
ENDIF
EXIT
ENDIF
lntemp = INT(num % i) && to get the modulo for the current power
IF lntemp > 0 && if >0 need to place a 1 in the string
lntemp = 1
num = INT(num - (i/2)) && adjust num for next power
ENDIF
i = i * 2 && increment power holder
lcstring = ALLTRIM(STR(lntemp))+lcstring && add 1/0 to lcstring
ENDDO
lcstring = PADL(lcstring,lnbits,'0') && take care of smaller nums
RETURN lcstring
Chris Zangarine
Software Development Engineer
Pipeline Compliance System (PCS)
American Innovations