原文:PFC
本文拟结合PFC中所提供的pfc_n_cst_numerical对象,讲解如何在PB脚本中实现位操作以及二进制与十进制相互转换。
(一)编写十进制转换成二进制的函数:
public function string of_binary (long al_decimal);integer li_remainder
string ls_binary=''
If IsNull(al_decimal) or al_decimal< 0 Then
string ls_null
SetNull(ls_null)
Return ls_null
End If
If al_decimal = 0 Then
Return '0'
End If
Do Until al_decimal= 0
li_remainder = mod(al_decimal, 2)
al_decimal = al_decimal /2
ls_binary = string(li_remainder) + ls_binary
Loop
Return ls_binary
end function
(二)编写二进制转换成为十进制的函数:
public function long of_decimal (string as_binary);integer li_cnt
long ll_len
char lch_char[]
long ll_decimal=0
If IsNull(as_binary) or Len(as_binary)<=0 then
long ll_null
SetNull(ll_null)