反转内存的函数    


//按单字节反转内存的函数procedure ReverseMemory(P: PByte; Len: Integer); overload;var  B: Byte;  P2: PByte;begin  P2 := P;  Inc(P2, Len - 1);  while Integer(P) < Integer(P2) do  begin    B := P^;    P^ := P2^;    P2^ := B;    Inc(P);    Dec(P2);  end;end;//按双字节反转内存的函数procedure ReverseMemory(P: PWord; Len: Integer); overload;var  W: Word;  P2: PWord;begin  P2 := P;  Inc(P2, Len div 2 - 1);  while Integer(P) < Integer(P2) do  begin    W := P^;    P^ := P2^;    P2^ := W;    Inc(P);    Dec(P2);  end;end;//按四字节反转内存的函数procedure ReverseMemory(P: PInteger; Len: Integer); overload;var  I: Integer;  P2: PInteger;begin  P2 := P;  Inc(P2, Len div 4 - 1);  while Integer(P) < Integer(P2) do  begin    I := P^;    P^ := P2^;    P2^ := I;    Inc(P);    Dec(P2);  end;end;//调用测试procedure TForm1.Button1Click(Sender: TObject);var  bs: TBytes;  i: Integer;begin  SetLength(bs, 8);  for i := 0 to Length(bs) - 1 do bs[i] := i + 49;  ShowMessage(StringOf(bs)); {12345678}  for i := 0 to Length(bs) - 1 do bs[i] := i + 49;  ReverseMemory(PByte(bs), Length(bs));  ShowMessage(StringOf(bs)); {87654321}  for i := 0 to Length(bs) - 1 do bs[i] := i + 49;  ReverseMemory(PWord(bs), Length(bs));  ShowMessage(StringOf(bs)); {78563412}  for i := 0 to Length(bs) - 1 do bs[i] := i + 49;  ReverseMemory(PInteger(bs), Length(bs));  ShowMessage(StringOf(bs)); {56781234}end;


©著作权归作者所有:来自51CTO博客作者JLee79的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 【php基础入门】细说PHP中的函数声明与使用详解(重要)
  2. ActionScript 3.0 记要(1): 基本语法
  3. 几个和当前路径相关的新函数
  4. 将字符串转换成 UTF8 编码的函数
  5. 学 Win32 汇编[33] - 探讨 Win32 汇编的模块化编程
  6. 0428作业-函数
  7. 学 Win32 汇编[18]: 关于压栈(PUSH)与出栈(POP) 之二
  8. 学 Win32 汇编[19]: 查看二进制等相关函数
  9. php之函数,匿名函数与回调函数

随机推荐

  1. (004)CSS选择符(selector)
  2. HTML显示日期时间代码 - [js 特效代码]
  3. 这个html太奇怪了,源码看不到"下一页"字符
  4. 基于html属性为gulp构建过程添加条件
  5. 为什么v-align中的将文本放在图像下面
  6. 您试图显示配置为只允许执行和脚本权限的
  7. 为什么IE7没有正确地将 块复制到剪贴板?
  8. ThinkPHP生成静态页buildHtml方法
  9. HTML哪些是块级元素,哪些是行内元素、
  10. 使用Semantic-UI垂直对齐div