{ This constant definition is required by both Dec2Hex }
{ and Hex2Dec: }

CONST
  HexString : array [0..15] of char = '0123456789ABCDEF';

FUNCTION Dec2Hex (Num : word) : string;
{ Returns decimal value as hex string }
VAR
  Loop  : Byte;
  S     : string [10];

BEGIN
  S := '';                                 { empty string }   
  for Loop := 1 to 4 do begin              { do 4 chars }
    S := HexString [Lo (Num) and $F] + S;  { use 4 lowest bits } 
    Num := Num shr 4;                      { shift bits right 4 } 
    end;
  Dec2Hex := '$' + S;                      { return string } 
END;

