tohex.srf 741 B

1234567891011121314151617181920212223242526272829303132
  1. $PBExportHeader$tohex.srf
  2. global type tohex from function_object
  3. end type
  4. forward prototypes
  5. global function string tohex (long arg_i, integer arg_len)
  6. end prototypes
  7. global function string tohex (long arg_i, integer arg_len);// 将arg_i转换成长度为arg_len的十六进制字符串,去掉溢出高位
  8. char c[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}
  9. string rslt = ''
  10. long ll_tmp
  11. do while arg_i >= 16
  12. ll_tmp = mod(arg_i, 16)
  13. rslt = c[ll_tmp + 1] + rslt
  14. arg_i = arg_i / 16
  15. loop
  16. rslt = c[arg_i + 1] + rslt
  17. long rel_len
  18. rel_len = len(rslt)
  19. if rel_len > arg_len then
  20. rslt = right(rslt, arg_len)
  21. else
  22. long i
  23. for i = 1 to (arg_len - rel_len)
  24. rslt = '0' + rslt
  25. next
  26. end if
  27. return rslt
  28. end function