能否帮我将以下代码用delphi重写一下?急,谢谢int write_com(unsigned char Add, unsigned int *Point)
{
int ret;
unsigned char buffer[4];
unsigned char aa;
unsigned char bb;buffer[0] = (((*Point)&0x00F0)/0x10)+(((*Point)&0x000F)*0x10);
buffer[1] = ((((*Point)/0x100)&0x00F0)/0x10)+((((*Point)/0x100)&0x000F)*0x10);aa = buffer[0]>>4; //High byte
bb = buffer[0]<<4; //Low byte
buffer[0] = aa|bb;
aa = buffer[1]>>4;
bb = buffer[1]<<4;
buffer[1] = aa|bb;
ret = 0;

}有一个地方不知怎么处理 ((*Point)/0x100)&0x00F0  ,前面一步运算出来不是整型就不能再作位运算了。

解决方案 »

  1.   

    div 和 vc 的 / 是一样吗?取整除最后结果会不同吧
      

  2.   

    div 和 / 是一样的,都是舍弃小数点后的内容取整的。
      

  3.   

    var
      ret:integer;
      buffer:array [0..3]of char;
      aa,bb:byte;begin
      buffer[0]:=char((Point and $00F0) div $10 + (Point and $000F)* $10);
      buffer[1]:=char((((Point div $100) and $00F0) div $10)+(((Point div $100) and $000F)*$10));
      aa:=byte(buffer[0]) shr 4;
      bb:=byte(buffer[0]) shl 4;
      buffer[0]:= char(aa or bb);
      aa:=byte(buffer[1]) shr 4;
      bb:=byte(buffer[1]) shl 4;
      buffer[1]:= char(aa or bb);
      ret:=0;
    end;
      

  4.   

    function write_comm(Add:char;var Point:DWord):integer;
    var
      ret:integer;
      buffer:array [0..3]of char; 
      aa,bb:char;
      
    begin
      buffer[0]:=(Point and $00F0) div $10 + (Point and $000F)* $10;
      buffer[1]:= (((Point div $100) and $00F0) div $10)+(((Point div $100) and $000F)*$10);
      aa:=buffer[0] shr 4;
      bb:=buffer[0] shl 4;
      buffer[0]:= aa or bb;
      aa:=buffer[1] shr 4;
      bb:=buffer[1] shl 4;
      buffer[1]:= aa or bb;
      ret:=0;
    end;
      

  5.   

    呵~~,更正下,这是我调试过的。
    function write_comm(Add:char;var Point:DWord):integer;
    var
      ret:integer;
      buffer:array [0..3]of char;
      aa,bb:byte;begin
      buffer[0]:=char((Point and $00F0) div $10 + (Point and $000F)* $10);
      buffer[1]:=char((((Point div $100) and $00F0) div $10)+(((Point div $100) and $000F)*$10));
      aa:=byte(buffer[0]) shr 4;
      bb:=byte(buffer[0]) shl 4;
      buffer[0]:= char(aa or bb);
      aa:=byte(buffer[1]) shr 4;
      bb:=byte(buffer[1]) shl 4;
      buffer[1]:= char(aa or bb);
      ret:=0;
    end;