请问在Delphi中怎样对十六进制的数据进行位操作,比如移位操作,以及十六进制的数怎么表示? (50分)

P

plf22

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在Delphi中怎样对十六进制的数据进行位操作,比如移位操作,以及十六进制的数怎么表示
 
$20
呵呵

 
shl 左移
shr 右移
...
等等
 
shl,shr左移右移
 
十进制的数怎么转换成十六进制的数,用什么函数,各位帮帮忙,做不出来,我就会不了家了
 
IntToHex()
 
实在是感谢Nizvoo兄弟,还有事请教,我现在有个十进制数组,要把他做成以下形式
x=0
x=x or a[3]
x<<8
x=x or a[2]
x<<8
x=x or a[1]
x<<8
x=x or a[0]
最后得出X,我实在写不出,能不能写个例子给我学习学习,我再加50分,感谢感谢!!

 
你是不是分四种情况求X?
不太明白你的意思?
 
就是顺着这个过程运行下来,求最后的结果,a[]就是个数组,里面是十进制的数,我就是不会
操作十进制的数移位,是不是需要先将数组转换成十六进制,那个X不知该定成什么类型的数
 
不懂需求啊。痛苦。我理解力严重有问题了
 
我写了一段,就是结构好像不对,你看看
var inf:longint;
mo:array [0..3] of integer;
i:integer;
begin
mo[0]:=1;
mo[1]:=2;
mo[2]:=3;
mo[3]:=4;
for i:=3 to 0 do
begin
inf:=inf or mo;
if i<>0 then inf:=inf shl 8;
end;
label1.Caption:=inttostr(inf);
end;
 
首先
3 to 0
应该改为
3 downto 0吧
我测试一下代码先
 
换成Downto,好像有效果,等老板检查过关了,就送你分,再谢你一遍
 
代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Inf: LongInt;
  mo: array[0..3] of LongInt;
  I: Byte;
  PLabel: ^TLabel;
begin
  mo[0] := 1;
  mo[1] := 2;
  mo[2] := 3;
  mo[3] := 4;
  New(PLabel);
  PLabel := @Label1;
  for I := 0 to 3 do
  begin
    Inf := mo[I]
//Inf要初始始化吗?你没有啊
    Inf := Inf or mo[I];
    if I <> 0 then
      Inf := Inf shl 8;
    PLabel^.Caption := IntToStr(Inf);
    Inc(PLabel);

  end;

end;



end.
 
输出


1
512
768
1024
 
到现在我还是不知道你要做个什么东西啊

Nizvoo@etang.com
 
为了还原Modem传过来的数据,谢谢!
 
顶部