请问各位DELPHI里有没有把十六进制转换为二进制的函数。
解决方案 »
- 如何使用ShellExcute显示HTML文件(十分火急)!!!
- sql问题
- 关于正玄函数的小问题(很简单的)在线等
- 急!!!!!!!!!是什么原因产生这个错误 A CALL TO AN OS FUNCTION FAILED
- 请大家帮忙看一下,门诊费用查询SQL语句是否可以这样写?
- 如何解決"Read failure"的問題﹖
- 想用程序A来监控程序B的运行,请问程序A如何判断程序B在运行啊?请指点
- 请有没有适合中文财务格式的控件下载(如速达的效果一样的)?
- 如何使用TDatabase组件?急!
- SetLocaleInfo 没效
- 请问:怎样在数据库里存取JPG类型的图片?急!急!!谢谢大家!
- 新生报到
function HexToInt(Hex : string) : Cardinal;
const cHex = '0123456789ABCDEF';
var mult,i,loop : integer;
begin
result := 0;
mult := 1;
for loop := length(Hex) downto 1 do begin
i := pos(Hex[loop],cHex)-1;
if (i < 0) then i := 0;
inc(result,(i*mult));
mult := mult * 16;
end;
end; function IntToBin(Value : integer; NumBits : byte) : string;
var lp0 : integer;
begin
result := '';
for lp0 := 0 to NumBits-1 do begin
if ((Value and (1 shl (lp0))) <> 0) then begin
result := #$31 + result;
end else result := #$30 + result;
end;
end; function BinToInt(Bin : string) : integer;
var mult,lp0 : integer;
begin
result := 0;
mult := 0;
for lp0 := length(Bin) downto 1 do begin
if Bin[lp0] = #$31 then begin
inc(result,(1 shl mult));
end;
inc(mult);
end;
end; function BinToHex(Bin : string; Digits : integer) : string;
begin
result := IntToHex(BinToInt(Bin),Digits);
end; function HexToBin(Hex : string; NumBits : byte) : string;
begin
result := IntToBin(HexToInt(Hex),NumBits);
end; // Below are also some code usefull for testing if a string is in binary, hex or decimal form. function IsStrDec(Value : string) : boolean;
var lp0 : integer;
begin // returns true on empty strings, since equal to zero
result := true;
for lp0 := 1 to length(Value) do begin
result := result and ((Ord(Value[lp0]) >= $30) and (Ord(Value[lp0]) <= $39));
end;
end; function IsStrHex(Value : string) : boolean;
var lp0 : integer;
begin
result := true;
for lp0 := 1 to length(Value) do begin
case Ord(Upcase(Value[lp0])) of
$30..$39, $41..$46: result := result and true;
else
result := false;
end;
end;
end; function IsStrBin(Value : string) : boolean;
var lp0 : integer;
begin
result := true;
for lp0 := 1 to length(Value) do begin
case Ord(Upcase(Value[lp0])) of
$30..$31: result := result and true;
else
result := false;
end;
end;
end;