zoukankan      html  css  js  c++  java
  • CHAR和HEX互相转换

    Function StrToHexStr(Const S: String): String; //字符串转换成16进制字符串(方法一) 
    Var 
      I: Integer; 
    Begin 
      For I := 1 To Length(S) Do 
      Begin 
        If I = 1 Then 
          Result := IntToHex(Ord(S[1]), 2) 
        Else Result := Result + ' ' + IntToHex(Ord(S[I]), 2); 
      End; 
    End; 
    
    function strToHexStr(str:string):string; //字符串转换成16进制字符串(方法二)  
    var 
    c:char;  
    ss:string;  
    begin 
    while str<>'' do begin 
    c:=str[1];  
    ss:=ss+format('%0x',[ord(c)]);  
    delete(str,1,1);  
    end;  
    strtohexStr:= ss;  
    end;  
    
    Function HexStrToStr(Const S: String): String; //16进制字符串转换成字符串 
    Var 
      t: Integer; 
      ts: String; 
      M, Code: Integer; 
    Begin 
      t := 1; 
      Result := ''; 
      While t <= Length(S) Do 
      Begin 
        While (t <= Length(S)) And (Not (S[t] In ['0'..'9', 'A'..'F', 'a'..'f'])) Do 
          Inc(t); 
        If (t + 1 > Length(S)) Or (Not (S[t + 1] In ['0'..'9', 'A'..'F', 'a'..'f'])) Then 
          ts := '$' + S[t] 
        Else 
          ts := '$' + S[t] + S[t + 1]; 
        Val(ts, M, Code); 
        If Code = 0 Then 
          Result := Result + Chr(M); 
        Inc(t, 2); 
      End; 
    End; 
    
  • 相关阅读:
    Problem F
    Problem L
    Problem L
    Problem B
    Problem B
    读书笔记-Java设计模式
    读书笔记-内存初始化和清理
    读书笔记- 一切都是对象
    Android多点触控技术实战,自由地对图片进行缩放和移动
    Native开发与JNI机制详解
  • 原文地址:https://www.cnblogs.com/Bung/p/2048335.html
Copyright © 2011-2022 走看看