您的位置:首页 > 编程语言 > Delphi

delphi 判断大小端方法

2016-01-28 13:23 561 查看
 type

  int32  = LongInt;

  uint32 = Longword;

  int16  = SmallInt;

  uint16 = Word;  //

  int8   = ShortInt;

  uint8  = Byte;

type
T_E_ByteOrder =(

    EBO_unknown = 0,

    EBO_LittleEndian = 1,

    EBO_BigEndian = 2 ) ;

Function FindMachineTransferSyntax(): T_E_ByteOrder;

var

  localByteOrderFlag: T_E_ByteOrder ;

  tl: record

        case msg: integer of

          0: (ul: uint32);

          1: (uc: array[0..3]of uint8);

      end;

  ts: record

        case msg: integer of

          0: (us: uint16);

          1: (uc: array[0..1]of uint8);

      end;

  bflag,bflag1: uint8;

begin

  tl.msg := 0;

  tl.ul := 1;

  ts.msg :=0;

  ts.us := 1;

  bflag := (tl.uc[1] or tl.uc[2] or tl.uc[3]);

  bflag1:= (tl.uc[0] or tl.uc[1] or tl.uc[2]);

  if (tl.uc[0] = 1)and (bflag = 0)and (ts.uc[0] = 1)and (ts.uc[1] = 0) then

    localByteOrderFlag := EBO_LittleEndian

  else

    if (tl.uc[3] = 1)and(bflag1 = 0)and (ts.uc[1] = 1)and(ts.uc[0] = 0) then

      localByteOrderFlag := EBO_BigEndian

    else

      localByteOrderFlag := EBO_unknown;

  result := localByteOrderFlag;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: