>I am trying to convert a character field (which is really a character represetation of a binary number, for example, 01010) to decimal (in this case 10). Is there a built-in function in VFP that can do that?
>
>How about the reverse (going from decimal to binary)?
Aristotle,
There's no way to go to and from binary to decimal and the reverse in VFP, like you can with hexadecimal representation. So you have to "roll your own"
lcbin = "01010"
lnlast = LEN(lcbin)
store 0 to lnresult, lnexp
FOR lni = lnlast TO 1 STEP - 1
lcchar = SUBSTR(lcbin, lni, 1)
IF lcchar = "1"
lnresult = lnresult + (2 ^ lnexp)
ENDIF
lnexp = lnexp + 1
NEXT
? lnresult
lcresult = ""
FOR lni = 0 TO 31
IF BITTEST(lnresult, lni)
lcresult = "1" + lcresult
ELSE
lcresult = "0" + lcresult
ENDIF
NEXT
? lcresult
George
Ubi caritas et amor, deus ibi est