function HexToValue(const S : String) : String;
var
I : Integer;
begin
SetLength(Result, Length(S) div 2);
for I := 0 to (Length(S) div 2) - 1 do
begin
Result[I+1] := Char(StrToInt('$'+Copy(S,(I*2)+1, 2)));
end;
end;
Hex 문자열 "303132333435" 이 있다면
문자열 "012345"로 변환해주는 함수이네요
음...
정확하게 일치하진 않지만
비슷한 용도로 만들어진 함수가 이미 vcl에 있습니다.
HexToBin 이라구..
HexToBin을 이용하여 위 HexToValue를 구현하면..
//델파이 버젼
function HexToValue2(const S : String) : String;
begin
SetLength(Result, Length(S) div 2);
HexToBin(PChar(S),PChar(Result),Length(S) div 2);
end;
C++Builder버젼은 ?
String __fastcall HexToValue(String s)
{
String sRslt;
sRslt.SetLength(s.Length()/2);
HexToBin(s.c_str(),sRslt.c_str(),s.Length()/2);
return sRslt;
}
그리고 HexToBin 함수가 있으면
BinToHex라는 함수가 있을것 같지 않습니까?
다음 링크를 보면 BinToHex함수를 이용하여 간단한 HexViewser를 만든것이 있습니다.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=919
그럼..
두박자 님이 쓰신 글 :
: 안녕하세요
:
: 델파이 암호화 소스를 변환하려 하는데
:
: Char(StrToInt('$'+Copy(S,(I*2)+1, 2)))
:
: 이부분이 이해가 안돼네요..... 고수님들 도움좀 부탁드립니다.
:
: 전체소스인데요
: //----------------------------------------------------------
: // Hexadecimal로 구성된 문자열을 Byte 데이터로 변환
: function HexToValue(const S : String) : String;
: var
: I : Integer;
: begin
: SetLength(Result, Length(S) div 2);
: for I := 0 to (Length(S) div 2) - 1 do
: begin
: Result[I+1] := Char(StrToInt('$'+Copy(S,(I*2)+1, 2)));
: end;
: end;
:
: //----------------------------------------------------------
:
: 전 이렇게 변환했거든요 잘 안돼네요 ^^
:
: String __fastcall HexToValue(const String S)
: {
: int I;
: String ru;
: ru.SetLength(S.Length() / 2);
: int itmp;
: String stmp;
: for (I = 0; I<(S.Length() / 2)-1; I++)
: {
: stmp = S[I*2+1] + S[I*2+2];
: ru[I+1] = char (StrToInt(stmp));
: // ru[I+1] = char(StrToInt('$'+Copy(S,(I*2)+1, 2)));
: }
: return ru;
: }
:
: 도움 부탁드립니다.