kornalius
10-05-2007, 07:12 PM
Here are two nice little functions that will convert a binary string to integer and another that will convert an integer to a binary string. These functions will be part of PPL 1.40.
func IntToBin(num$, len$)
* i$ = 1;
* Result$ = "";
* while ((i$ <= num$) or (Length(Result$) < len$))
*** if (num$ & i$ == i$)
***** Result$ = "1" % Result$;
*** else
***** Result$ = "0" % Result$;
*** end;
*** i$ *= 2;
* end;
* return (result$);
end;
func BinToInt(Binary$)
* Result$ = 0;
* j$ = 1;
* for (i$, Length(Binary$) - 1, 0)
*** Result$ = Result$ + int(chr(Binary$[i$])) * j$;
*** j$ *= 2;
* end;
* return(Result$);
end;
func IntToBin(num$, len$)
* i$ = 1;
* Result$ = "";
* while ((i$ <= num$) or (Length(Result$) < len$))
*** if (num$ & i$ == i$)
***** Result$ = "1" % Result$;
*** else
***** Result$ = "0" % Result$;
*** end;
*** i$ *= 2;
* end;
* return (result$);
end;
func BinToInt(Binary$)
* Result$ = 0;
* j$ = 1;
* for (i$, Length(Binary$) - 1, 0)
*** Result$ = Result$ + int(chr(Binary$[i$])) * j$;
*** j$ *= 2;
* end;
* return(Result$);
end;