谁知道delphi中进制转换怎么写 例如十进制的转成二进制 谢谢 5
展开全部
//16进制转2进制
function MyHexToBin(Hexadecimal: string): string;
const
BCD: array [0..15] of string =
('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111',
'1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111');
var
i: integer;
begin
result :='';
for i := Length(Hexadecimal) downto 1 do
Result := BCD[StrToInt('$' + Hexadecimal[i])] + Result;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
BinStr,HexStr : string;
begin
i := 123456;
//数字转16进制
HexStr:= IntTohex(i,0);
BinStr := MyHexToBin(HexStr);
showmessage(BinStr);
end;
function MyHexToBin(Hexadecimal: string): string;
const
BCD: array [0..15] of string =
('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111',
'1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111');
var
i: integer;
begin
result :='';
for i := Length(Hexadecimal) downto 1 do
Result := BCD[StrToInt('$' + Hexadecimal[i])] + Result;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
BinStr,HexStr : string;
begin
i := 123456;
//数字转16进制
HexStr:= IntTohex(i,0);
BinStr := MyHexToBin(HexStr);
showmessage(BinStr);
end;
展开全部
Function Mod_num(n1,n2: Integer): Integer;
begin
Result := n1 - n1 div n2 * n2;
end;
Function Reverse(s: string): string;
var
num, i: Integer;
St: string;
begin
num:=Length(s);
st:='';
For i:=num DownTo 1 do
Begin
st:=st+s[i];
End;
Result:=st;
end;
Function DecToBin(Value: Integer): String; // 十进制转变成二进制
var
ST: string;
n: Integer;
begin
ST:='';
n:=value;
While n>=2 Do
Begin
st:=st+IntToStr(mod_num(n,2));
n:=n div 2;
End;
st:=st+IntToStr(n);
for n := 1 to 4 - Length(st) do
begin
st := st + '0';
end;
Result:=reverse(st);
end;
begin
Result := n1 - n1 div n2 * n2;
end;
Function Reverse(s: string): string;
var
num, i: Integer;
St: string;
begin
num:=Length(s);
st:='';
For i:=num DownTo 1 do
Begin
st:=st+s[i];
End;
Result:=st;
end;
Function DecToBin(Value: Integer): String; // 十进制转变成二进制
var
ST: string;
n: Integer;
begin
ST:='';
n:=value;
While n>=2 Do
Begin
st:=st+IntToStr(mod_num(n,2));
n:=n div 2;
End;
st:=st+IntToStr(n);
for n := 1 to 4 - Length(st) do
begin
st := st + '0';
end;
Result:=reverse(st);
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
问的说法不专业,整数本来就是二进制。
可能是想问:十进整数如何转换成二进字符串?
可能是想问:十进整数如何转换成二进字符串?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询