{"id":86,"date":"2009-06-14T06:56:09","date_gmt":"2009-06-14T14:56:09","guid":{"rendered":"http:\/\/www.abin.cn\/?p=86"},"modified":"2009-06-14T06:56:09","modified_gmt":"2009-06-14T14:56:09","slug":"hextostr%e5%87%bd%e6%95%b0%e5%92%8cstrtohex%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.abin.cn\/?p=86","title":{"rendered":"HexToStr\u51fd\u6570\u548cStrToHex\u51fd\u6570"},"content":{"rendered":"<p>HexToStr\u51fd\u6570\u548cStrToHex\u51fd\u6570<!--more--><\/p>\n<p><code><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #000000;\"><strong>function<\/strong><\/span> TransChar(AChar: Char): Integer;<br \/>\n<span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\n<span style=\"color: #000000;\"><strong>if<\/strong><\/span> AChar <span style=\"color: #000000;\"><strong>in<\/strong><\/span> ['0'..'9'] <span style=\"color: #000000;\"><strong>then<\/strong><\/span><br \/>\nResult := Ord(AChar) - Ord('0')<br \/>\n<span style=\"color: #000000;\"><strong>else<\/strong><\/span><br \/>\nResult := 10 + Ord(AChar) - Ord('A');<br \/>\n<span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<br \/>\n<span style=\"color: #000000;\"><strong>function<\/strong><\/span> StrToHex(AStr: <span style=\"color: #000000;\"><strong>string<\/strong><\/span>): <span style=\"color: #000000;\"><strong>string<\/strong><\/span>;<br \/>\n<span style=\"color: #000000;\"><strong>var<\/strong><\/span><br \/>\nI ,Len: Integer;<br \/>\ns:char;<br \/>\n<span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\nlen:=length(AStr);<br \/>\nResult:='';<br \/>\n<span style=\"color: #000000;\"><strong>for<\/strong><\/span> i:=1 <span style=\"color: #000000;\"><strong>to<\/strong><\/span> len\u00a0\u00a0<span style=\"color: #000000;\"><strong>do<\/strong><\/span><br \/>\n<span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\ns:=AStr[i];<br \/>\nResult:=Result +' '+IntToHex(Ord(s),2); <\/span><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #770000;\"><em>\/\/\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a16\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c<br \/>\n<\/em><\/span> <\/span><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #770000;\"><em>\/\/\u5e76\u4ee5\u7a7a\u683c\u95f4\u9694\u3002<br \/>\n<\/em><\/span> <span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<br \/>\nDelete(Result,1,1); <\/span><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #770000;\"><em>\/\/\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u7a7a\u683c<br \/>\n<\/em><\/span><span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<br \/>\n<span style=\"color: #000000;\"><strong>function<\/strong><\/span> HexToStr(AStr: <span style=\"color: #000000;\"><strong>string<\/strong><\/span>): <span style=\"color: #000000;\"><strong>string<\/strong><\/span>;<br \/>\n<span style=\"color: #000000;\"><strong>var<\/strong><\/span><br \/>\nI,len : Integer;<br \/>\nCharValue: Word;<br \/>\nTmp:<span style=\"color: #000000;\"><strong>string<\/strong><\/span>;<br \/>\ns:char;<br \/>\n<span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\nTmp:='';<br \/>\nlen:=length(Astr);<br \/>\n<span style=\"color: #000000;\"><strong>for<\/strong><\/span> i:=1 <span style=\"color: #000000;\"><strong>to<\/strong><\/span> len\u00a0\u00a0<span style=\"color: #000000;\"><strong>do<\/strong><\/span><br \/>\n<span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\ns:=Astr[i];<br \/>\n<span style=\"color: #000000;\"><strong>if<\/strong><\/span> s &lt;&gt; ' ' <span style=\"color: #000000;\"><strong>then<\/strong><\/span> Tmp:=Tmp+ <span style=\"color: #000000;\"><strong>string<\/strong><\/span>(s);<br \/>\n<span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<br \/>\nResult := '';<br \/>\n<span style=\"color: #000000;\"><strong>For<\/strong><\/span> I := 1 <span style=\"color: #000000;\"><strong>to<\/strong><\/span> Trunc(Length(Tmp)<\/span><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #770000;\"><em>\/2) do<br \/>\n<\/em><\/span> <span style=\"color: #000000;\"><strong>begin<\/strong><\/span><br \/>\nResult := Result + ' ';<br \/>\nCharValue := TransChar(Tmp[2*I-1])*16 + TransChar(Tmp[2*I]);<br \/>\n<span style=\"color: #000000;\"><strong>if<\/strong><\/span> (charvalue &lt; 32) <span style=\"color: #000000;\"><strong>or<\/strong><\/span> (charvalue &gt; 126)\u00a0\u00a0<span style=\"color: #000000;\"><strong>then<\/strong><\/span> Result[I] := '.' <\/span><span style=\"font-family: \u65b0\u5b8b\u4f53;\"><span style=\"color: #770000;\"><em>\/\/\u975e\u53ef\u89c1\u5b57\u7b26\u586b\u5145<br \/>\n<\/em><\/span> <span style=\"color: #000000;\"><strong>else<\/strong><\/span> Result[I] := Char(CharValue);<br \/>\n<span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<br \/>\n<span style=\"color: #000000;\"><strong>end<\/strong><\/span>;<\/span><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HexToStr\u51fd\u6570\u548cStrToHex\u51fd\u6570<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.abin.cn\/index.php?rest_route=\/wp\/v2\/posts\/86"}],"collection":[{"href":"https:\/\/www.abin.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.abin.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.abin.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.abin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":0,"href":"https:\/\/www.abin.cn\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.abin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.abin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.abin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}