Hello everyone,
Does anyone know if there is a function in pxplus to convert a binary number (0000000001000000) to a decimal number(64)?, I read about the dec () function but it's not what I want.
Please clarify:
Is the source value just ones and zeroes?
Is it a string or numeric value?
Give this a try:
0010 ! begin
0020 x$="0000000001000000"
0030 print dec($00$+fn_atob$(x$))
0040 end
0100 FN_BTOA:! ^100
0110 ! Function which converts ASCII data to its binary representation
0120 def fn_btoa$(local x$)=hta(tbl(hta(tbl(hta(x$),"0123456789ABCDEF",
0120:$00010203101112132021222330313233$)),"0123",$00011011$))
0200 FN_ATOB:! ^100
0210 ! Function which returns ASCII value corresponding to a string a binary data
0220 def fn_atob$(local x$)=ath(tbl(ath(tbl(ath(x$),$00011011$,"0123")),
0220:$00010203101112132021222330313233$,"0123456789ABCDEF"))
thanks chris I will try this routine.
Actually here is another solution:
0010 begin
0020 LET x$="0000000001000000"
0030 LET value=0
0040 WHILE x$<>""
0050 LET value=2*value+NUM(x$(1,1))
0060 LET x$=x$(2)
0070 WEND
0080 PRINT value
Or perhaps as a simple recursive function:
0010 LET x$="0000000001000000"
0020 DEF FN_val(LOCAL x$)=TBL(x$="",NUM(MID(x$,-1))+2*FN_val(MID(x$,-1,-100)),0)
0030 PRINT FN_val(x$)
Mike:
Does this mean the limit on recursive calls has been eliminated? Or changed?
According to the documentation, one of the reasons for throwing Error #25:
QuoteCannot exceed limit on number of recursive calls to a user defined function. (Maximum of 10 recursive calls, ten levels deep.)
Or does defining the function with Local variables override the limit?
Thanks in advance for the clarification.
No, the limit still exists its just been updated to 100 in PxPlus as of Version 7.
This means the recursive function I posted would only work for binary strings of 100 bytes or less (not likely a problem in most business applications).
We will get the manual updated.