$PBExportHeader$n_func_radix.sru forward global type n_func_radix from nonvisualobject end type end forward global type n_func_radix from nonvisualobject autoinstantiate end type type variables private: char HEXDIGIT[] = "0123456789ABCDEF" string BINSTR[] = {'0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111'} end variables forward prototypes public function unsignedlong bin2dec (string bin) public function string dec2bin (unsignedlong num) public function string dec2hex (unsignedlong num) public function unsignedlong hex2dec (string hex) public function string bin2hex (string bin) public function string hex2bin (string hex) public function string byte2bin (byte b) public function string byte2hex (byte b) public function byte hex2byte (string hex) public function byte bin2byte (string bin) end prototypes public function unsignedlong bin2dec (string bin);char binchar[] long i,ll,result string bindigitstr bindigitstr = "01" binchar = bin ll = upperbound(binchar) for i = 1 to ll result *= 2 if binchar[i] = '1' then result ++ next return result end function public function string dec2bin (unsignedlong num);byte r string bin do while num > 0 r = mod(num,2) num /= 2 if r = 1 then bin = '1' + bin else bin = '0' + bin end if loop return bin end function public function string dec2hex (unsignedlong num);byte r string hex do while num > 15 r = mod(num,16) num /= 16 hex = HEXDIGIT[r + 1] + hex loop hex = HEXDIGIT[num + 1] + hex return hex end function public function unsignedlong hex2dec (string hex);char hexchar[] long i,ll,result string hexdigitstr hexdigitstr = HEXDIGIT hexchar = hex ll = upperbound(hexchar) for i = 1 to ll result *= 16 result += pos(hexdigitstr,hexchar[i]) - 1 next return result end function public function string bin2hex (string bin);int p char hex[],binchar[] long i,k,ll byte temp p = mod(len(bin) , 4) if p <> 0 then p = 4 - p bin = fill("0",p) + bin binchar = bin ll = upperbound(binchar) / 4 for i = 1 to ll temp = 1 k ++ if binchar[k] = '1' then temp += 8 k ++ if binchar[k] = '1' then temp += 4 k ++ if binchar[k] = '1' then temp += 2 k ++ if binchar[k] = '1' then temp += 1 hex[i] = HEXDIGIT[temp] next return hex end function public function string hex2bin (string hex);string hexdigitstr char bin[],binchar[],hexchar[] long i,j,ll hexchar = hex ll = upperbound(hexchar) hexdigitstr = HEXDIGIT for i = 1 to ll binchar = BINSTR[pos(hexdigitstr,hexchar[i])] j ++ bin[j] = binchar[1] j ++ bin[j] = binchar[2] j ++ bin[j] = binchar[3] j ++ bin[j] = binchar[4] next return bin end function public function string byte2bin (byte b);string hex hex = HEXDIGIT[b / 16 + 1] + HEXDIGIT[mod(b , 16) + 1] return BINSTR[pos(HEXDIGIT , left(hex , 1))] + BINSTR[pos(HEXDIGIT , right(hex , 1))] end function public function string byte2hex (byte b);return HEXDIGIT[b / 16 + 1] + HEXDIGIT[mod(b , 16) + 1] end function public function byte hex2byte (string hex);return (pos(HEXDIGIT , left(hex , 1)) - 1) * 16 + pos(HEXDIGIT , right(hex , 1)) - 1 end function public function byte bin2byte (string bin);char bchar[] byte b bchar = bin if bchar[1] = '1' then b += 128 if bchar[2] = '1' then b += 64 if bchar[3] = '1' then b += 32 if bchar[4] = '1' then b += 16 if bchar[5] = '1' then b += 8 if bchar[6] = '1' then b += 4 if bchar[7] = '1' then b += 2 if bchar[8] = '1' then b += 1 return b end function on n_func_radix.create call super::create TriggerEvent( this, "constructor" ) end on on n_func_radix.destroy TriggerEvent( this, "destructor" ) call super::destroy end on
n_func_radix
于 2024-05-29 16:51:55 首次发布