{***********************************************************************}
{									}
{ __ToHexStr  Return the hexadecimal representation of an integer	}
{									}
{ function  __ToHexStr(IntValue : longint; Size : word) : string;	}
{									}
{	      IntValue	The integer-type expression to be converted to	}
{			a hexadecimal string representing the same	}
{			value.						}
{	      Size	The size in bytes of IntValue.			}
{									}
{ Description __ToHexStr returns a hexadecimal string representing the	}
{	      the unsigned value of IntValue.  The returned string	}
{	      will always be 2, 4, or 8 characters long, corresponding	}
{	      to bytes and shortints, integers and words, and		}
{	      longints respectively, padded on the left with zeroes.	}
{	      Although __ToHexStr could be implemented using a call	}
{	      to __ToRadStr, for efficiency hexadecimal conversion is	}
{	      handled as a special case because it is used so often.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __ToHexStr(IntValue : longint; Size : word) : string;

  const
    HexCheck : array[0..15] of char = '0123456789ABCDEF';

  var
    I	    : integer;
    TempStr : string[8];

  begin {__ToHexStr}

    { Exit immediately if Size is an invalid parameter. 		}

    if ((Size <> 1) and (Size <> 2) and (Size <> 4)) then
       begin
	 __ToHexStr := '';
	 Exit
       end;

    Length(TempStr) := 8;
    for I := 0 to 7 do
      begin
	TempStr[8 - i] := HexCheck[IntValue and $000F];
	IntValue := IntValue shr 4
      end;

    I := 2 * Size;		       { The returned string size	}
    __ToHexStr := Copy(TempStr,8 - I + 1,I)

  end;	{__ToHexStr}
