捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:超短精简进制转换 (二进制/十进制/十六进制)
riverqh 22757 2006/4/8 20:48:34
dna32r 的写得不错,呵呵,Str、Val似乎是Delphi的RTL实现吧?也可能是我记错了。

楼主的有的也是不错,不过在简单的转换用Format似乎有些小题大做了,何况这些转换在应用很频繁的地方,是否应该考虑一下性能?
dna32r 22623 2006/4/3 21:25:12
我以为我已经很菜了~没有想到还有比我还菜的~菜就菜呗..吹牛就是你的不对了~~~

完全用API完成:..uses Windows;
function IntToStr(I: integer): string;
begin
  Str(I, Result);
end;

function StrToInt(S: string): integer;
begin
 Val(S, Result, Result);
end;

function HexToInt(Const HexValue: String) : Integer;
begin
  Val('$'+HexValue, Result, Result);
end;

function IntToHex(Const Value: Integer): string;
const
  HexChars: array[0..15] of Char = '0123456789ABCDEF';
var
  iTemp: Integer;
  i: Integer;
begin
  Result := '';
  i := 0;
  while i<4 do
  begin
    case i of
      0: iTemp := Value shr 24 and $FF;
      1: iTemp := Value shr 16 and $FF;
      2: iTemp := Value shr 8 and $FF;
      3: iTemp := Value and $FF;
    end;
    Result := Result + HexChars[iTemp div 16];
    Result := Result + HexChars[iTemp mod 16];
    Inc(i);
  end;
end;

function LowerCase(const S: string): String;
begin
  Result:=CharLower(Pchar(S));
end;

function UpperCase(const S: string): String;
begin
  Result:=CharUpper(Pchar(S));
end;

多学习少吹牛..这个是我平时没事的时候~自己写的..
luckygame 22325 2006/3/24 11:17:18
有很多错误,建议修改后再使用。
beyondbit 22317 2006/3/23 20:03:32
怎么把一个字符串一个一个的取出来转换成8位的二进制数据呢?
iamdream 22311 2006/3/23 14:15:33
呀,刚才写错了:
function ToHexStr(const S: string): string;
const
  csHexChar: array[0..15] of Char = '0123456789ABCDEF';
var
  i: Integer;
begin
  SetLength(Result, Length(S) shl 1);
  for i := Length(S) downto 1 do begin
    Result[i * 2]    := csHexChar[Byte(S[i]) and $F];
    Result[i * 2 -1] := csHexChar[(Byte(S[i]) and $F0) shr 4];
  end;
end;
iamdream 22310 2006/3/23 14:05:29
最后一个,对大字符串,还是得用这个:
function ToHexStr(const S: string): string;
const
  csHexChar: array[0..15] of Char = '0123456789ABCDEF';
var
  i: Integer;
begin
  SetLength(Result, Length(S) shl 1);
  for i := Length(S) downto 1 do begin
    Result[i * 2]    := csHexChar[Byte(Result[i]) and $F];
    Result[i * 2 -1] := csHexChar[(Byte(Result[i]) and $F0) shr 4];
  end;
end;
wqy888 22294 2006/3/22 10:23:53
不错!早晚有用!
iceker 22279 2006/3/21 13:30:56
顶\  有没有汉字转换?
第一页 上一页 下一页 最后页 有 8 条纪录 共1页 1 - 8
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表