Module

XlfHex

Path

C:\CPRS\CPRS30\XuDigSig\XlfHex.pas

Last Modified

7/15/2014 3:26:44 PM

Comments

This is a file to support converting arrays and strings
from to Hex.

Procedures

Name Owner Declaration Scope Comments
HexStrToArray - procedure HexStrToArray(str: string; var pba: array of byte); Interfaced -

Functions

Name Owner Declaration Scope Comments
ArrayToHexStr - function ArrayToHexStr(pba: Pchar; len: integer): string; Interfaced
The first argument is a byte array with the data
to convert.
pbData: Array[0..20] of byte
 hex := ArrayToHexStr(pbData, length)


Module Source

1     unit XlfHex;
2     //This is a file to support converting arrays and strings
3     //from to Hex.
4     interface
5     
6     uses
7       Classes, SysUtils;
8     
9       function ArrayToHexStr(pba: Pchar; len: integer): string;
10      procedure HexStrToArray(str: string; var pba: array of byte);
11    implementation
12    
13    function ArrayToHexStr;
14    //The first argument is a byte array with the data
15    //to convert.
16    //pbData: Array[0..20] of byte
17    // hex := ArrayToHexStr(pbData, length)
18    var
19       i,v: integer;
20       s: string;
21    begin
22         //Convert the Array to a Hex string
23         Result := '';
24         s := '';
25         for i := 0 to len-1 do
26             begin
27              v := integer(pba[i]);
28              s := s + intToHex(v,2);
29              end;
30         Result := lowercase(s);
31    end;
32    
33    procedure HexStrToArray;
34    var
35       ix, ox, hx, bv: integer;
36       ch: string;
37       rdy: boolean;
38    const Hexvalues = '0123456789abcdef';
39    begin
40         str := lowercase(str);
41         ox := 0;  //Set the starting index for the output.
42         bv := 0;
43         rdy := false;
44         for ix := 1 to length(str) do
45         begin
46              ch := copy(str, ix, 1);
47              hx := pos(ch, Hexvalues);
48              bv := bv*16 + (hx-1);
49              if rdy then
50                begin
51                pba[ox] := bv;
52                inc(ox);
53                bv := 0;
54                end;
55              rdy := not rdy;
56         end;
57    end;
58    
59    end.

Module Calls (2 levels)

-

Module Called-By (2 levels)

-