zoukankan      html  css  js  c++  java
  • Delphi byte[]转换为int

    http://bbs.csdn.net/topics/330082331 

    1、

    var
      buf: array[0..1] of byte;
      bus: array[0..3] of byte;
      si:SmallInt ;
      i:Integer ;
    begin
      buf[0] := $01;
      buf[1] := $02;
      bus[0] := $00;
      bus[1] := $01;
      bus[2] := $02;
      bus[3] := $03;
    
      Move(buf,si,SizeOf(SmallInt) );
      ShowMessage(IntToStr(si));
    
      Move(bus,i,SizeOf(Integer) );
      ShowMessage(IntToStr(i));

    2、

    类型转换
    用个Integer指针直接指向字节数组就OK了,如果就想看看转换结果的话,MOVE都不用了
    var
      buf : array[0..3] of byte;
      Pint:PInteger;
    begin
      buf[0] := $00;
      buf[1] := $01;
      buf[2] := $02;
      buf[3] := $03;
      Pint:=@buf[0];
      ShowMessage(IntToStr( Pint^));
    end;

    3、

    var
      buf : array[0..1] of byte;
      bus : array[0..3] of byte;
      function ByteToHex(InByte:byte):shortstring;
        const Digits:array[0..15] of char='0123456789ABCDEF';
      begin
        result:=digits[InByte shr 4]+digits[InByte and $0F];
      end;
      function BinArrayToString(aArray: array of Byte): string;
      var
        i: integer;
      begin
        result:='';
        for i:= Low(aArray) to High(aArray) do
        begin
          result:= result + ByteToHex(aArray[i]);
        end;
        Result:= IntToStr(StrToInt('$'+result));
      end;
    begin
      buf[0] := $01;
      buf[1] := $02;
      showmessage(BinArrayToString(buf));
      bus[0] := $00;
      bus[1] := $01;
      bus[2] := $02;
      bus[3] := $03;
      showmessage(BinArrayToString(bus));
    end;
  • 相关阅读:
    .net core使用EasyNetQ做EventBus
    .NET Core DI 手动获取注入对象
    设置Jexus开机启动
    centos7开放关闭防火墙端口
    linux防火墙开放端口
    转 Jexus-5.6.3使用详解
    Mysql存储过程
    Reids笔记
    Lucene笔记
    Spring Junit 测试用例
  • 原文地址:https://www.cnblogs.com/zhrong/p/5736393.html
Copyright © 2011-2022 走看看