System.Classes.HexToBin
Delphi
function HexToBin(const Text: PChar; TextOffset: Integer;
var Buffer: TBytes; BufOffset: Integer; Count: Integer): Integer; overload;
function HexToBin(const Text: TBytes; TextOffset: Integer;
var Buffer: TBytes; BufOffset: Integer; Count: Integer): Integer;
function HexToBin(Text: PWideChar; Buffer: Pointer; BufSize: Integer): Integer;
function HexToBin(const Text: PWideChar; var Buffer; BufSize: Integer): Integer;
function HexToBin(Text: PAnsiChar; Buffer: PAnsiChar; BufSize: Integer): Integer;
function HexToBin(Text: PWideChar; Buffer: PAnsiChar; BufSize: Integer): Integer;
function HexToBin(Text: PAnsiChar; var Buffer; BufSize: Integer): Integer;
function HexToBin(const Text: PAnsiChar; Buffer: Pointer; BufSize: Integer): Integer;
C++
extern DELPHI_PACKAGE int __fastcall HexToBin(const System::WideChar * Text, int TextOffset, System::Sysutils::TBytes &Buffer, int BufOffset, int Count)/* overload */;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.Classes.pas System.Classes.hpp |
System.Classes | System.Classes |
Description
Converts a string of hexadecimal digits to the corresponding binary value.
Call HexToBin to convert the hexadecimal string Text
to the binary value that the string represents.
This function receives the following parameters:
Parameter | Description |
---|---|
|
Pointer to a string representing a hexadecimal value. For example: "1decaf".
|
|
Number of characters to skip at the beginning of the input string. For example, if |
|
Pointer to an array of bytes that will receive the value of the hexadecimal input string. For example, for the input string "1decaf", the output binary value would be |
|
Number of bytes to skip at the beginning of the output array of bytes. For example, if |
|
Number of bytes (pairs of hexadecimal characters) to convert into the output array of bytes.
|
You can call HexToBin with or without specifying an offset for the input string (TextOffset
) or the output buffer (BufOffset
). However, you must specify either both offsets or specify neither of them.
When HexToBin finds a character that is not a hexadecimal character, it stops converting and returns. For example, given the string "9abcdefg", HexToBin only converts "9abcde", as the next pair of characters ("fg") contains an invalid character ("g").
The return value of HexToBin depends on whether or not you specified offsets in the call to HexToBin:
- If you did specify offsets, the return value is the number of bytes read from the input string and written in binary into
Buffer
. For example, given the string "9abcdefg", it returns 3, as it reads 3 bytes ("9abcde", "fg" contains an invalid character). - If you did not specify offsets, the return value is the number of bytes that were not read from the input string and written in binary into
Buffer
(BufSize
- bytes written intoBuffer
). For example, given the string "9abcdefg" and aBufSize
of 4, it returns 1, as it reads 3 out of 4 expected bytes ("9abcde", "fg" contains an invalid character).