如何把16进制的串转化为二进制串 例如 $ff->11111111(10分)

  • 主题发起人 主题发起人 晓茜
  • 开始时间 开始时间
我只会把十进制转化为二进制

不过我想十六进制地转化为二进制地思路也一样
 
这个吗,
可以作一个多维的数组来实现吧,
把数字转成字符啊!
进行串扫描!一个一个的写进一个新的字符串中不得了
 
用以下函数:
shl, shr, and, IntToStr, StrToInt
 
prodruce ten_to_two(integer:num):string;
var i,j,temp:integer;
str:string;
begin
str:='';
for i:=0 to 7 do
begin
temp:=1;
for j:=1 to i do
temp:=temp*2;
if (num and temp)=temp then
str:=str+'1'
else
str:=str+'0';
end;
result:=str;
end;
 
function HexToBin(HexStr: String): String;
const
BinLst1: array ['0'..'9'] of String[4]
= ('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001');
BinLst2: array ['A'..'F'] of String[4]
= ('1010','1011','1100','1101','1110','1111');
HexChars: set of char = ['0'..'9', 'A'..'F', 'a'..'f'];
var
I, X: Integer;
ch: Char;
begin
X:= 0; Result:= '';
for I:= 1 to Length(HexStr) do
if HexStr in HexChars then begin
X:= I; Break;
end;
if X = 0 then Exit;
for I:= X to length(HexStr) do begin
ch:= upcase(HexStr);
case ch of
'0'..'9': Result:= Result + BinLst1[ch];
'A'..'F': Result:= Result + BinLst2[ch];
else Break;
end;{case}
end;
end;
 
谢谢各位了,我的qq号,被盗了!不能跟各位聊天了!
 
其实我的方法更简单,可惜我中午写错了一点东西,*^_^*
function ten_to_two(num:integer):string;
var i,j,temp:integer;
str:string;
begin
str:='';
for i:=0 to 7 do
begin
temp:=1;
for j:=1 to i do
temp:=temp*2;
if (num and temp)=temp then
str:='1'+str
else
str:='0'+str;
end;
result:=str;
end;
 
后退
顶部