如何将16进制转为2进制?

shanliying 2004-04-06 10:43:19
16进制文本串:3e000000000000010001fc
转为二进制文本串
...全文
120 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zswangII 2004-04-06
  • 打赏
  • 举报
回复
function HexToBin(mHex: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mHex) do
case mHex[I] of
'0' : Result := Result + '0000';
'1' : Result := Result + '0001';
'2' : Result := Result + '0010';
'3' : Result := Result + '0011';
'4' : Result := Result + '0100';
'5' : Result := Result + '0101';
'6' : Result := Result + '0110';
'7' : Result := Result + '0111';
'8' : Result := Result + '1000';
'9' : Result := Result + '1001';
'a', 'A': Result := Result + '1010';
'b', 'B': Result := Result + '1011';
'c', 'C': Result := Result + '1100';
'd', 'D': Result := Result + '1101';
'e', 'E': Result := Result + '1110';
'f', 'F': Result := Result + '1111';
else Result := Result + ' ';
end;
end; { HexToBin }
shanliying 2004-04-06
  • 打赏
  • 举报
回复
过程是不是这样:
比如0108a1先变成
00000001 00001000 10100001
然后变成三个字符在连接在一起成个字符串
shanliying 2004-04-06
  • 打赏
  • 举报
回复
看看我的转换,转出来就是不对!
function hextoascii(input:string;var output:string):boolean;
var
i,j:integer;
len:integer;
str:string;
bf:pchar;
aa:string;
begin
result:=false;
getmem(bf,1);
len:=length(input);
output:='';
for i:=1 to len do
begin
str:=input[i];
hextobin(pchar(str),bf,1);
output:=output+strpas(bf);
end;


end;
yurenjf 2004-04-06
  • 打赏
  • 举报
回复
HexTobin
web700 2004-04-06
  • 打赏
  • 举报
回复
转了十进制再转二进制
ztenv 2004-04-06
  • 打赏
  • 举报
回复
可以利用C语言中的算法来处理这个问题,我想在学C时一定涉及到了这个问题

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧