c代码翻译成delphi 代码

bitter_spill 2010-08-23 02:28:41
int __fastcall TMainForm::AscToBin(unsigned char *instr,int inlen,unsigned char *outstr)
{
int i;
unsigned char c,high,low;
for(i=0;i<inlen/2;i++)
{
c=instr[2*i];
if(c>='0'&&c<='9') high=c-0x30;
if(c>='A'&&c<='F') high=c-0x41+0x0a;
if(c>='a'&&c<='f') high=c-0x61+0x0a;

c=instr[2*i+1];
if(c>='0'&&c<='9')low=c-0x30;
if(c>='A'&&c<='F')low=c-0x41+0x0a;
if(c>='a'&&c<='F')low=c-0x61+0x0a;
outstr[i]=(high<<4)+low;
}
return inlen/2;
}
...全文
70 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bitter_spill 2010-08-25
  • 打赏
  • 举报
回复
谢谢,各位,结贴,散分。
JPEXE 2010-08-23
  • 打赏
  • 举报
回复
function AscToBin(instr: PAnsiChar; inlen: Integer; outstr: PByte): Integer;
var
i: Integer;
c: AnsiChar;
h: Byte;
l: Byte;
begin
for i := 0 to (inlen div 2) - 1 do
begin
c := instr^;
if c in ['0'..'9'] then h := Byte(c) - $30;
if c in ['A'..'F'] then h := Byte(c) - $41 + $0A;
if c in ['a'..'f'] then h := Byte(c) - $61 + $0A;

c := (instr + 1)^;
if c in ['0'..'9'] then l := Byte(c) - $30;
if c in ['A'..'F'] then l := Byte(c) - $41 + $0A;
if c in ['a'..'f'] then l := Byte(c) - $61 + $0A;

outstr^ := (h shl 4) + l;

Inc(instr, 2);
Inc(outstr, 1);
end;

Result := inlen div 2;
end;

PS:调用前需要给outstr参数分配内存,长度为inlen的1/2。
白耗子 2010-08-23
  • 打赏
  • 举报
回复

function TForm1.DelphiAscToBin(instr:array of Byte;inlen:Integer;outstr:array of Byte):Integer;
var
i:Integer;
c,high,low:Byte;
begin
for i:=0 to inlen div 2 do
begin
c:=instr[i];

if not ( Chr(c) in ['0'..'9']) then
high:=c-$30;
//下面的你自己换下 同理可得
end;
end;
bitter_spill 2010-08-23
  • 打赏
  • 举报
回复
一些语法老是报错误,没有C语言简便。
在线等。。。
亮剑_ 2010-08-23
  • 打赏
  • 举报
回复
这个不太复杂吧,建议自己试一下
Mastering Delphi 7(Delphi7从入门到精通)虽然是英文版的,不过是好书呀,压缩包含配书代码!Introduction(目录): Part I - Foundations (基础) Chapter 1 - Delphi 7 and Its IDE (DELPHI7及集成环境) Chapter 2 - The Delphi Programming Language (DELPHI7编程语言) Chapter 3 - The Run-Time Library (运行库) Chapter 4 - Core Library Classes (核心类库) Chapter 5 - Visual Controls (虚拟组件) Chapter 6 - Building the User Interface (建立用户界面) Chapter 7 - Working with Forms (从窗体开始学习) Part II - Delphi Object-Oriented Architectures (对象向导体系) Chapter 8 - The Architecture of Delphi Applications (应用程序体系) Chapter 9 - Writing Delphi Components (写Delphi组件) Chapter 10 - Libraries and Packages (库和包) Chapter 11 - Modeling and OOP Programming (with ModelMaker) (面向对象程序程序设计建造模块) Chapter 12 - From COM to COM+ (从。。。不用翻译了吧) Part III - Delphi Database-Oriented Architectures (数据库向导体系) Chapter 13 - Delphi's Database Architecture (数据体系) Chapter 14 - Client/Server with dbExpress (dbE.. 的客户/服务模式) Chapter 15 - Working with ADO (应用ADO) Chapter 16 - Multitier DataSnap Applications (多层DataSnap应用) Chapter 17 - Writing Database Components (写数据组件) Chapter 18 - Reporting with Rave (Rave报表) Part IV - Delphi, the Internet, and a .NET Preview (。。。预览) Chapter 19 - Internet Programming: Sockets and Indy (互联网编成。。。) Chapter 20 - Web Programming with WebBroker and WebSnap (。。。) Chapter 21 - Web Programming with IntraWeb (。。。) Chapter 22 - Using XML Technologies (运用XML技术) Chapter 23 - Web Services and SOAP (。。。) Chapter 24 - The Microsoft .NET Architecture from the Delphi Perspective (Delphi的.NET体系) Chapter 25 - Delphi for .NET Preview: The Language and the RTL Appendix A - Extra Delphi Tools by the Author (附录A) Appendix B - Extra Delphi Tools from Other Sources (附录B) Appendix C - Free Companion Books on Delphi (附录C) Index List of Figures List of Tables List of Listings List of Sidebars(我随便翻译的,不准笑,“。。。”表示没得翻。)

5,392

社区成员

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

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