TBits 既是一个类。我有一个例子: unit MainU;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); const IntSize = 12; var st: TBits; i: integer; begin st := TBits.Create; Edit1.Clear; st.Size := IntSize; Randomize; for i := 0 to st.Size - 1 do begin st.Bits[i] := Odd(Random(100)); Edit1.Text := Edit1.Text + IntToStr(Ord(st.Bits[i])); end; st.Free; end;end.
to 楼上 你是能实现对位级的操作,很感谢你 不过,还是没回答我的提问阿 怎么定义它,利用Tbits 难道一定得用Byte定义它了么?期待...
据我所知,IP报头不需要定义到位,如下是我对IP报头的定义: tag_IP = record IHL: Byte; Service: Byte; Length: WORD; ID: WORD; Flags: WORD; TTL: Byte; Protocol: Byte; Checksum: WORD; Source, Destination: DWORD; end; 对于其中的标志位,如Flags是要取到位的,对于这样的操作只要用and操作即可,如下 if Flags and 4=4 then 这样取到的是Flags中的第3位
Byte, 相关操作shl, shr ,请看帮助!
to inbud(清风侠) and ltf_ty(兔八哥) 谢谢你,相关IP报头的定义,我也看到过. 不过总想这样定义,本来IP数据报规定(指我们的规定)总共多少字节,现在变大了,其实其它方面倒是无所谓的,多几个字节就多几个字节,分包/速度各方面一点影响都没有.if Flags and 4=4 then 这样取到的是Flags中的第3位上句何解?谢谢
不过我觉得还是用 byte 或者 word 类型的东西要好使一些。
我想用它来定义IP数据报头(如,4字节)
呵呵
怎么实现呢?
用 LongWord (4字节的),不过 IP 数据报头我不明白。
又错了,老是这样
是4位,sorry
TBits.Size 获取和设置大小;
TBits.Bits[Index: Integer]:Boolean;
从 0..Size - 1 每个位的值。
能不能象这样:
var
b: ??? ;
delphi的基本数据类型是编译器识别的。你完全可以写个类.
unit MainU;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
const
IntSize = 12;
var
st: TBits;
i: integer;
begin
st := TBits.Create;
Edit1.Clear;
st.Size := IntSize;
Randomize;
for i := 0 to st.Size - 1 do
begin
st.Bits[i] := Odd(Random(100));
Edit1.Text := Edit1.Text + IntToStr(Ord(st.Bits[i]));
end;
st.Free;
end;end.
你是能实现对位级的操作,很感谢你
不过,还是没回答我的提问阿
怎么定义它,利用Tbits
难道一定得用Byte定义它了么?期待...
tag_IP = record
IHL: Byte;
Service: Byte;
Length: WORD;
ID: WORD;
Flags: WORD;
TTL: Byte;
Protocol: Byte;
Checksum: WORD;
Source, Destination: DWORD;
end;
对于其中的标志位,如Flags是要取到位的,对于这样的操作只要用and操作即可,如下
if Flags and 4=4 then
这样取到的是Flags中的第3位
谢谢你,相关IP报头的定义,我也看到过.
不过总想这样定义,本来IP数据报规定(指我们的规定)总共多少字节,现在变大了,其实其它方面倒是无所谓的,多几个字节就多几个字节,分包/速度各方面一点影响都没有.if Flags and 4=4 then
这样取到的是Flags中的第3位上句何解?谢谢
期待...