sucks result in converting with hextobin or bintohex fuction?

sucks result in converting with hextobin or bintohex fuction?
I wanna convert hex to binary.
in hex editor converter
HEX STRING
FFD8FFFE002446007B0 smoothly become "ÿØÿþ $F {" and vice versa

but if I use Delphi hextobin
FFD8FFFE002446007B0 become ␀F

and if I use Delphi bintohex
ÿØÿþ $F { become FF00D800FF00FE0020002400460020007B00

are there any another ways to convert it, as easy as hex editor

here is the code
procedure Tfrm1.btnToStringClick(Sender: TObject);
var
LStr1, LStr2: WideString;

begin
LStr1 := Memo2.Lines.Text;
SetLength(LStr2, Length(LStr1) div 4);
HexToBin(PWideChar(LStr1), LStr2[1], Length(LStr1) div SizeOf(Char));
Memo1.Lines.Text := LStr2;
end;

procedure Tfrm1.btToHexClick(Sender: TObject);
var
LStr1, LStr2: String;

begin
LStr1 := Memo1.Lines.Text;
SetLength(LStr2, Length(LStr1) * 4);
BinToHex(LStr1[1], PWideChar(LStr2), Length(LStr1) * SizeOf(Char));
Memo2.Lines.Text := LStr2;
end;

Comments

  1. David Heffernan that text represent of the binary

    FF -> 1111 1111 -> ÿ

    ReplyDelete
  2. Nope, you need to learn about text encodings, which you don't seem cogniscent of yet.

    ReplyDelete
  3. Cakar Kucing
    There can't be a function StrToHex without knowing the encoding.
    BinToHex will convert binary data to hexadecimal.

    FF and 1111 1111 are binary.
    ÿ is the character "LATIN SMALL LETTER Y WITH DIAERESIS" that encoded to:
    - UTF8 is represented binary as: C3 BF
    - UTF16 is represented binary as: 00 FF
    - Windows-1252 is represented binary as: FF
    See here also:
    fileformat.info - Unicode Character 'LATIN SMALL LETTER Y WITH DIAERESIS' (U+00FF)

    ReplyDelete

Post a Comment