在Delhi中怎样定义"位"的数据类型呢?(无内容)_

tongdings 2002-09-24 09:12:58
在Delhi中怎样定义"位"的数据类型呢?(无内容)_
...全文
37 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
tongdings 2002-09-25
  • 打赏
  • 举报
回复
to inbud(清风侠)

你能不能跟我讲讲自定义IP头实现收发数据的机理阿?

给你加分?
期待...
tongdings 2002-09-25
  • 打赏
  • 举报
回复
to inbud(清风侠) and ltf_ty(兔八哥)
谢谢你,相关IP报头的定义,我也看到过.
不过总想这样定义,本来IP数据报规定(指我们的规定)总共多少字节,现在变大了,其实其它方面倒是无所谓的,多几个字节就多几个字节,分包/速度各方面一点影响都没有.

if Flags and 4=4 then
这样取到的是Flags中的第3位

上句何解?谢谢
ltf_ty 2002-09-25
  • 打赏
  • 举报
回复
Byte, 相关操作shl, shr ,请看帮助!
1nbud 2002-09-25
  • 打赏
  • 举报
回复
据我所知,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位
tongdings 2002-09-25
  • 打赏
  • 举报
回复
to 楼上
你是能实现对位级的操作,很感谢你
不过,还是没回答我的提问阿
怎么定义它,利用Tbits
难道一定得用Byte定义它了么?

期待...
CloneCenter 2002-09-24
  • 打赏
  • 举报
回复
TBits 既是一个类。我有一个例子:
unit MainU;

interface

uses
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.
tongdings 2002-09-24
  • 打赏
  • 举报
回复
楼上的,当说无妨...
westfly 2002-09-24
  • 打赏
  • 举报
回复
用掩码来实现啊
tongdings 2002-09-24
  • 打赏
  • 举报
回复
我对位操作不熟.望指点
tongdings 2002-09-24
  • 打赏
  • 举报
回复
楼上的,怎么写
请教了
stanely 2002-09-24
  • 打赏
  • 举报
回复
不能按位定义基本数据类型。
delphi的基本数据类型是编译器识别的。

你完全可以写个类.
tongdings 2002-09-24
  • 打赏
  • 举报
回复
那你说说看怎么定义一个2位变量b?
能不能象这样:
var
b: ??? ;
CloneCenter 2002-09-24
  • 打赏
  • 举报
回复
TBits:
TBits.Size 获取和设置大小;
TBits.Bits[Index: Integer]:Boolean;
从 0..Size - 1 每个位的值。
tongdings 2002-09-24
  • 打赏
  • 举报
回复

又错了,老是这样
是4位,sorry
CloneCenter 2002-09-24
  • 打赏
  • 举报
回复
4 字节是吧?
用 LongWord (4字节的),不过 IP 数据报头我不明白。
tongdings 2002-09-24
  • 打赏
  • 举报
回复
TBits不是吧?
怎么用?
tongdings 2002-09-24
  • 打赏
  • 举报
回复
谁说对了,马上给分!
tongdings 2002-09-24
  • 打赏
  • 举报
回复
to CloneCenter(复制中心)
我想用它来定义IP数据报头(如,4字节)
呵呵
怎么实现呢?
CloneCenter 2002-09-24
  • 打赏
  • 举报
回复
TBits 是不是可以考虑一下。可以看看 delphi 的帮助。
不过我觉得还是用 byte 或者 word 类型的东西要好使一些。
tongdings 2002-09-24
  • 打赏
  • 举报
回复
先UP一下吧

5,391

社区成员

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

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