16进制:$//strtoint()//IntToHex
解决方案 »
- Com+
- 如何将窗体的创建参数化
- 今天编译程序时出了一个未知的错误:Internal error: URW3959
- DLL中如何传DataSet?
- 关于文件打开的方法和效率问题?
- 请问怎样将一个Delphi的DBDEMOS中的animals.dbf表的表结构保存到一个新表中?
- 4.如何將系統的DB導航條的Delete時的英文确認提示改為中文的?
- 为什么Gis控件MapObject2.0在升级到delphi6.0后无法正常使用!
- 请问如何在Delphi中调用可执行文件
- 是高手吗?
- 在flash动画中夹杂木马程序的可能性!!!
- 我做了个报表,预览时的汉字显示总是有的挤在一起,有的又离的很远,打印时却没问题。
delphi中没有2进制的类或函数吧?要用就自己写了
function DecToBinStr(n: integer): string;
var
S: string;
i: integer;
Negative: boolean;
begin
if n < 0 then
Negative := true
else
Negative := False; n := Abs(n);
for i := 1 to SizeOf(n) * 8 do
begin
if n < 0 then
S := S + '1'
else
S := S + '0'; n := n shl 1;
end;
Delete(S,1,Pos('1',S) - 1);//remove leading zeros
if Negative then
S := '-' + S;
Result := S;
end;如何把一个16进制字符转换为10进制
(1)方法1
Function HexToDec(const Value :Integer ) : string;
var
s : string;
begin
s := '$' + IntToStr(Value);
Result := InToStr(StrToInt(s));
end;(2)方法2
Funtion HexToDec(const Value :Integer) : string;
CONST HEX : ARRAY['A'..'F'] OF INTEGER = (10,11,12,13,14,15);
VAR
str : String;
In : Integer;
i : integer;
BEGIN
Str := UpperCase(IntToStr(Value));
Int := 0;
FOR i := 1 TO Length(str) DO
IF str[i] < 'A' THEN
Int := Int * 16 + ORD(str[i]) - 48
ELSE
Int := Int * 16 + HEX[str[i]];
Result := IntToStr(Int);
end;
这样的答案你是否可以给我加分呢?
StrToInt('$'+'B4')
10->16
IntToHex 函数
16->2
HexToBin 函数
shl的运行结果有问题,不过我已经自己搞定了10到2的转换
你的16到10的方法非常有缺陷,因为你用integer作为参数,根本就不能输a,b,c,d,e,f这几个数,所以不行。
系统提供的strToInt,IntToHex,HexToBin使用是不能运行通过,说是没有作为override的原函数,莫名其妙,我直接拷贝的他的例子来运行都这个样子
Math;const
cScaleChar = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';function IntToDigit(mNumber: Integer; mScale: Byte; mLength: Integer = 0): string;
var
I, J: Integer;
begin
Result := '';
I := mNumber;
while (I >= mScale) and (mScale > 1) do begin
J := I mod mScale;
I := I div mScale;
Result := cScaleChar[J + 1] + Result;
end;
Result := cScaleChar[I + 1] + Result;
if mLength > 0 then
for I := 1 to mLength - Length(Result) do
Result := '0' + Result;
end; { IntToDigit }function DigitToInt(mDigit: string; mScale: Byte): Integer;
var
I: Byte;
L: Integer;
begin
Result := 0;
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], cScaleChar) - 1) *
Trunc(IntPower(mScale, I - 1));
end; { DigitToInt }