Byte building

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gianmaria I.

    Byte building

    Hi,
    having a BitArray, how can i extract bits to create a System.byte

    as in the example...

    With
    BitArray bits
    and
    Byte myNewByte

    bits[0] to bits[7] => myNewByte



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Byte building

    Gianmaria,

    You will want to call the CopyTo method, passing in a byte array with
    one element, like so:

    // The byte array of one element.
    byte[] bytes = new byte[1];

    // Call the CopyTo method.
    bits.CopyTo(byt es, 0);

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Gianmaria I." <nowaytoknow@ho thot.it> wrote in message
    news:eZmzfxocFH A.3564@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    > having a BitArray, how can i extract bits to create a System.byte
    >
    > as in the example...
    >
    > With
    > BitArray bits
    > and
    > Byte myNewByte
    >
    > bits[0] to bits[7] => myNewByte
    >
    >
    >[/color]


    Comment

    • Nathan Kovac

      #3
      Re: Byte building

      It has been since beta since I did any of this, but here is some old source
      code that might help you out. Someone on this same forum had helped me
      about 4 years ago with a similar problem when I was working out a protocal
      for an online game. If you look at what I am doing there are a couple
      choices that might help you accomplish what you need. Pay special attention
      to how I calculate the data length from the first 4 bytes of my packet, this
      will probably be your most efficient method of doing what you want. Here is
      my code.

      using System;

      using System.Runtime. Serialization.F ormatters.Binar y;

      using System.IO;

      using System.Diagnost ics;

      namespace MudClient

      {

      /// <summary>

      /// Summary description for Packet.

      /// </summary>

      ///

      public enum PacketType:byte

      {

      IgnoreThisPacke t,

      BroadcastToServ er,

      LoginToServer,

      LoginAccepted,

      LoginDenied,

      LoginReqestfrom Server,

      QuitToServer,

      QuitToClient,

      ServerShuttingD own,

      SetCommandLineT oClient,

      CommandToServer ,

      CommandToClient ,

      TextToClient,

      PingClient,

      PongServer,

      AbbrTextToClien t,

      RequestAbbrText Value,

      SendAbbrTextVal ue,

      ClearAbbrTextOn Client

      }

      public class Packet

      {

      private byte command;

      private int dataLength=0;

      private byte[] Data;

      public byte[] PacketData

      {

      get

      {

      return Data;

      }

      set

      {

      Data=value;

      dataLength=Data .Length;

      }

      }

      public int Length

      {

      get

      {

      if (Data==null)

      return 5;

      else

      return dataLength+5;

      }

      }

      public PacketType Command

      {

      get

      {

      return (PacketType)com mand;

      }

      set

      {

      command=(byte)v alue;

      }

      }

      public string StrPacketData

      {

      get {return System.Text.Enc oding.ASCII.Get String(Data);}

      set

      {

      Data=System.Tex t.Encoding.ASCI I.GetBytes(valu e.ToCharArray() );

      dataLength=Data .Length;

      }

      }

      public Packet()

      {

      Command=PacketT ype.IgnoreThisP acket;

      }

      public Packet(PacketTy pe cmd)

      {

      Command=cmd;

      }

      public Packet(byte[] thisdata)

      {

      if (thisdata.Lengt h>0)

      command=thisdat a[0];

      if (thisdata.Lengt h>5)

      {

      dataLength =

      (((int)thisdata[4]) << 24) +

      (((int)thisdata[3]) << 16) +

      (((int)thisdata[2]) << 8) +

      ((int)thisdata[1]);

      if (dataLength>0)

      {

      Data=new Byte[dataLength];

      Array.Copy(this data,5,Data,0,d ataLength);

      }

      }

      }

      public Packet(PacketTy pe cmd, byte[] thisdata)

      {

      Command=cmd;

      Data=thisdata;

      dataLength=Data .Length;

      }

      public Packet(PacketTy pe cmd, string thisdata)

      {

      Command=cmd;

      Data=System.Tex t.Encoding.ASCI I.GetBytes(this data.ToCharArra y());

      dataLength=Data .Length;

      Debug.WriteLine ("setting dataLength to "+dataLengt h);

      }

      public byte[] Serialize()

      {

      int len=this.Length ;

      byte[] tempcmd=new byte[len];

      tempcmd[0] = command;

      tempcmd[1] = (byte)(dataLeng th & 0xff);

      tempcmd[2] = (byte)((dataLen gth >> 8) & 0xff);

      tempcmd[3] = (byte)((dataLen gth >>16) & 0xff);

      tempcmd[4] = (byte)((dataLen gth >>24) & 0xff);


      if (len>5)

      {

      Array.Copy(Data ,0,tempcmd,5,da taLength);

      }

      return tempcmd;

      }

      }

      }


      "Gianmaria I." <nowaytoknow@ho thot.it> wrote in message
      news:eZmzfxocFH A.3564@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi,
      > having a BitArray, how can i extract bits to create a System.byte
      >
      > as in the example...
      >
      > With
      > BitArray bits
      > and
      > Byte myNewByte
      >
      > bits[0] to bits[7] => myNewByte
      >
      >
      >[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Byte building

        Or, you could use the CopyTo method on the BitArray class. =)


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Nathan Kovac" <nate@tctelco.n et> wrote in message
        news:uNp2tCpcFH A.720@TK2MSFTNG P15.phx.gbl...[color=blue]
        > It has been since beta since I did any of this, but here is some old
        > source code that might help you out. Someone on this same forum had
        > helped me about 4 years ago with a similar problem when I was working out
        > a protocal for an online game. If you look at what I am doing there are a
        > couple choices that might help you accomplish what you need. Pay special
        > attention to how I calculate the data length from the first 4 bytes of my
        > packet, this will probably be your most efficient method of doing what you
        > want. Here is my code.
        >
        > using System;
        >
        > using System.Runtime. Serialization.F ormatters.Binar y;
        >
        > using System.IO;
        >
        > using System.Diagnost ics;
        >
        > namespace MudClient
        >
        > {
        >
        > /// <summary>
        >
        > /// Summary description for Packet.
        >
        > /// </summary>
        >
        > ///
        >
        > public enum PacketType:byte
        >
        > {
        >
        > IgnoreThisPacke t,
        >
        > BroadcastToServ er,
        >
        > LoginToServer,
        >
        > LoginAccepted,
        >
        > LoginDenied,
        >
        > LoginReqestfrom Server,
        >
        > QuitToServer,
        >
        > QuitToClient,
        >
        > ServerShuttingD own,
        >
        > SetCommandLineT oClient,
        >
        > CommandToServer ,
        >
        > CommandToClient ,
        >
        > TextToClient,
        >
        > PingClient,
        >
        > PongServer,
        >
        > AbbrTextToClien t,
        >
        > RequestAbbrText Value,
        >
        > SendAbbrTextVal ue,
        >
        > ClearAbbrTextOn Client
        >
        > }
        >
        > public class Packet
        >
        > {
        >
        > private byte command;
        >
        > private int dataLength=0;
        >
        > private byte[] Data;
        >
        > public byte[] PacketData
        >
        > {
        >
        > get
        >
        > {
        >
        > return Data;
        >
        > }
        >
        > set
        >
        > {
        >
        > Data=value;
        >
        > dataLength=Data .Length;
        >
        > }
        >
        > }
        >
        > public int Length
        >
        > {
        >
        > get
        >
        > {
        >
        > if (Data==null)
        >
        > return 5;
        >
        > else
        >
        > return dataLength+5;
        >
        > }
        >
        > }
        >
        > public PacketType Command
        >
        > {
        >
        > get
        >
        > {
        >
        > return (PacketType)com mand;
        >
        > }
        >
        > set
        >
        > {
        >
        > command=(byte)v alue;
        >
        > }
        >
        > }
        >
        > public string StrPacketData
        >
        > {
        >
        > get {return System.Text.Enc oding.ASCII.Get String(Data);}
        >
        > set
        >
        > {
        >
        > Data=System.Tex t.Encoding.ASCI I.GetBytes(valu e.ToCharArray() );
        >
        > dataLength=Data .Length;
        >
        > }
        >
        > }
        >
        > public Packet()
        >
        > {
        >
        > Command=PacketT ype.IgnoreThisP acket;
        >
        > }
        >
        > public Packet(PacketTy pe cmd)
        >
        > {
        >
        > Command=cmd;
        >
        > }
        >
        > public Packet(byte[] thisdata)
        >
        > {
        >
        > if (thisdata.Lengt h>0)
        >
        > command=thisdat a[0];
        >
        > if (thisdata.Lengt h>5)
        >
        > {
        >
        > dataLength =
        >
        > (((int)thisdata[4]) << 24) +
        >
        > (((int)thisdata[3]) << 16) +
        >
        > (((int)thisdata[2]) << 8) +
        >
        > ((int)thisdata[1]);
        >
        > if (dataLength>0)
        >
        > {
        >
        > Data=new Byte[dataLength];
        >
        > Array.Copy(this data,5,Data,0,d ataLength);
        >
        > }
        >
        > }
        >
        > }
        >
        > public Packet(PacketTy pe cmd, byte[] thisdata)
        >
        > {
        >
        > Command=cmd;
        >
        > Data=thisdata;
        >
        > dataLength=Data .Length;
        >
        > }
        >
        > public Packet(PacketTy pe cmd, string thisdata)
        >
        > {
        >
        > Command=cmd;
        >
        > Data=System.Tex t.Encoding.ASCI I.GetBytes(this data.ToCharArra y());
        >
        > dataLength=Data .Length;
        >
        > Debug.WriteLine ("setting dataLength to "+dataLengt h);
        >
        > }
        >
        > public byte[] Serialize()
        >
        > {
        >
        > int len=this.Length ;
        >
        > byte[] tempcmd=new byte[len];
        >
        > tempcmd[0] = command;
        >
        > tempcmd[1] = (byte)(dataLeng th & 0xff);
        >
        > tempcmd[2] = (byte)((dataLen gth >> 8) & 0xff);
        >
        > tempcmd[3] = (byte)((dataLen gth >>16) & 0xff);
        >
        > tempcmd[4] = (byte)((dataLen gth >>24) & 0xff);
        >
        >
        > if (len>5)
        >
        > {
        >
        > Array.Copy(Data ,0,tempcmd,5,da taLength);
        >
        > }
        >
        > return tempcmd;
        >
        > }
        >
        > }
        >
        > }
        >
        >
        > "Gianmaria I." <nowaytoknow@ho thot.it> wrote in message
        > news:eZmzfxocFH A.3564@tk2msftn gp13.phx.gbl...[color=green]
        >> Hi,
        >> having a BitArray, how can i extract bits to create a System.byte
        >>
        >> as in the example...
        >>
        >> With
        >> BitArray bits
        >> and
        >> Byte myNewByte
        >>
        >> bits[0] to bits[7] => myNewByte
        >>
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Nathan Kovac

          #5
          Re: Byte building

          Thanks, I learned something from this too.

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
          message news:ujfRhFpcFH A.3880@tk2msftn gp13.phx.gbl...[color=blue]
          > Or, you could use the CopyTo method on the BitArray class. =)
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Nathan Kovac" <nate@tctelco.n et> wrote in message
          > news:uNp2tCpcFH A.720@TK2MSFTNG P15.phx.gbl...[color=green]
          >> It has been since beta since I did any of this, but here is some old
          >> source code that might help you out. Someone on this same forum had
          >> helped me about 4 years ago with a similar problem when I was working out
          >> a protocal for an online game. If you look at what I am doing there are
          >> a couple choices that might help you accomplish what you need. Pay
          >> special attention to how I calculate the data length from the first 4
          >> bytes of my packet, this will probably be your most efficient method of
          >> doing what you want. Here is my code.
          >>
          >> using System;
          >>
          >> using System.Runtime. Serialization.F ormatters.Binar y;
          >>
          >> using System.IO;
          >>
          >> using System.Diagnost ics;
          >>
          >> namespace MudClient
          >>
          >> {
          >>
          >> /// <summary>
          >>
          >> /// Summary description for Packet.
          >>
          >> /// </summary>
          >>
          >> ///
          >>
          >> public enum PacketType:byte
          >>
          >> {
          >>
          >> IgnoreThisPacke t,
          >>
          >> BroadcastToServ er,
          >>
          >> LoginToServer,
          >>
          >> LoginAccepted,
          >>
          >> LoginDenied,
          >>
          >> LoginReqestfrom Server,
          >>
          >> QuitToServer,
          >>
          >> QuitToClient,
          >>
          >> ServerShuttingD own,
          >>
          >> SetCommandLineT oClient,
          >>
          >> CommandToServer ,
          >>
          >> CommandToClient ,
          >>
          >> TextToClient,
          >>
          >> PingClient,
          >>
          >> PongServer,
          >>
          >> AbbrTextToClien t,
          >>
          >> RequestAbbrText Value,
          >>
          >> SendAbbrTextVal ue,
          >>
          >> ClearAbbrTextOn Client
          >>
          >> }
          >>
          >> public class Packet
          >>
          >> {
          >>
          >> private byte command;
          >>
          >> private int dataLength=0;
          >>
          >> private byte[] Data;
          >>
          >> public byte[] PacketData
          >>
          >> {
          >>
          >> get
          >>
          >> {
          >>
          >> return Data;
          >>
          >> }
          >>
          >> set
          >>
          >> {
          >>
          >> Data=value;
          >>
          >> dataLength=Data .Length;
          >>
          >> }
          >>
          >> }
          >>
          >> public int Length
          >>
          >> {
          >>
          >> get
          >>
          >> {
          >>
          >> if (Data==null)
          >>
          >> return 5;
          >>
          >> else
          >>
          >> return dataLength+5;
          >>
          >> }
          >>
          >> }
          >>
          >> public PacketType Command
          >>
          >> {
          >>
          >> get
          >>
          >> {
          >>
          >> return (PacketType)com mand;
          >>
          >> }
          >>
          >> set
          >>
          >> {
          >>
          >> command=(byte)v alue;
          >>
          >> }
          >>
          >> }
          >>
          >> public string StrPacketData
          >>
          >> {
          >>
          >> get {return System.Text.Enc oding.ASCII.Get String(Data);}
          >>
          >> set
          >>
          >> {
          >>
          >> Data=System.Tex t.Encoding.ASCI I.GetBytes(valu e.ToCharArray() );
          >>
          >> dataLength=Data .Length;
          >>
          >> }
          >>
          >> }
          >>
          >> public Packet()
          >>
          >> {
          >>
          >> Command=PacketT ype.IgnoreThisP acket;
          >>
          >> }
          >>
          >> public Packet(PacketTy pe cmd)
          >>
          >> {
          >>
          >> Command=cmd;
          >>
          >> }
          >>
          >> public Packet(byte[] thisdata)
          >>
          >> {
          >>
          >> if (thisdata.Lengt h>0)
          >>
          >> command=thisdat a[0];
          >>
          >> if (thisdata.Lengt h>5)
          >>
          >> {
          >>
          >> dataLength =
          >>
          >> (((int)thisdata[4]) << 24) +
          >>
          >> (((int)thisdata[3]) << 16) +
          >>
          >> (((int)thisdata[2]) << 8) +
          >>
          >> ((int)thisdata[1]);
          >>
          >> if (dataLength>0)
          >>
          >> {
          >>
          >> Data=new Byte[dataLength];
          >>
          >> Array.Copy(this data,5,Data,0,d ataLength);
          >>
          >> }
          >>
          >> }
          >>
          >> }
          >>
          >> public Packet(PacketTy pe cmd, byte[] thisdata)
          >>
          >> {
          >>
          >> Command=cmd;
          >>
          >> Data=thisdata;
          >>
          >> dataLength=Data .Length;
          >>
          >> }
          >>
          >> public Packet(PacketTy pe cmd, string thisdata)
          >>
          >> {
          >>
          >> Command=cmd;
          >>
          >> Data=System.Tex t.Encoding.ASCI I.GetBytes(this data.ToCharArra y());
          >>
          >> dataLength=Data .Length;
          >>
          >> Debug.WriteLine ("setting dataLength to "+dataLengt h);
          >>
          >> }
          >>
          >> public byte[] Serialize()
          >>
          >> {
          >>
          >> int len=this.Length ;
          >>
          >> byte[] tempcmd=new byte[len];
          >>
          >> tempcmd[0] = command;
          >>
          >> tempcmd[1] = (byte)(dataLeng th & 0xff);
          >>
          >> tempcmd[2] = (byte)((dataLen gth >> 8) & 0xff);
          >>
          >> tempcmd[3] = (byte)((dataLen gth >>16) & 0xff);
          >>
          >> tempcmd[4] = (byte)((dataLen gth >>24) & 0xff);
          >>
          >>
          >> if (len>5)
          >>
          >> {
          >>
          >> Array.Copy(Data ,0,tempcmd,5,da taLength);
          >>
          >> }
          >>
          >> return tempcmd;
          >>
          >> }
          >>
          >> }
          >>
          >> }
          >>
          >>
          >> "Gianmaria I." <nowaytoknow@ho thot.it> wrote in message
          >> news:eZmzfxocFH A.3564@tk2msftn gp13.phx.gbl...[color=darkred]
          >>> Hi,
          >>> having a BitArray, how can i extract bits to create a System.byte
          >>>
          >>> as in the example...
          >>>
          >>> With
          >>> BitArray bits
          >>> and
          >>> Byte myNewByte
          >>>
          >>> bits[0] to bits[7] => myNewByte
          >>>
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Gianmaria I.

            #6
            Re: Byte building

            Thank you too, u really kind.
            "Nathan Kovac" <nate@tctelco.n et> ha scritto nel messaggio
            news:eEuTTJpcFH A.3712@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Thanks, I learned something from this too.
            >
            > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
            > in message news:ujfRhFpcFH A.3880@tk2msftn gp13.phx.gbl...[color=green]
            >> Or, you could use the CopyTo method on the BitArray class. =)
            >>
            >>
            >> --
            >> - Nicholas Paldino [.NET/C# MVP]
            >> - mvp@spam.guard. caspershouse.co m
            >>
            >> "Nathan Kovac" <nate@tctelco.n et> wrote in message
            >> news:uNp2tCpcFH A.720@TK2MSFTNG P15.phx.gbl...[color=darkred]
            >>> It has been since beta since I did any of this, but here is some old
            >>> source code that might help you out. Someone on this same forum had
            >>> helped me about 4 years ago with a similar problem when I was working
            >>> out a protocal for an online game. If you look at what I am doing there
            >>> are a couple choices that might help you accomplish what you need. Pay
            >>> special attention to how I calculate the data length from the first 4
            >>> bytes of my packet, this will probably be your most efficient method of
            >>> doing what you want. Here is my code.
            >>>
            >>> using System;
            >>>
            >>> using System.Runtime. Serialization.F ormatters.Binar y;
            >>>
            >>> using System.IO;
            >>>
            >>> using System.Diagnost ics;
            >>>
            >>> namespace MudClient
            >>>
            >>> {
            >>>
            >>> /// <summary>
            >>>
            >>> /// Summary description for Packet.
            >>>
            >>> /// </summary>
            >>>
            >>> ///
            >>>
            >>> public enum PacketType:byte
            >>>
            >>> {
            >>>
            >>> IgnoreThisPacke t,
            >>>
            >>> BroadcastToServ er,
            >>>
            >>> LoginToServer,
            >>>
            >>> LoginAccepted,
            >>>
            >>> LoginDenied,
            >>>
            >>> LoginReqestfrom Server,
            >>>
            >>> QuitToServer,
            >>>
            >>> QuitToClient,
            >>>
            >>> ServerShuttingD own,
            >>>
            >>> SetCommandLineT oClient,
            >>>
            >>> CommandToServer ,
            >>>
            >>> CommandToClient ,
            >>>
            >>> TextToClient,
            >>>
            >>> PingClient,
            >>>
            >>> PongServer,
            >>>
            >>> AbbrTextToClien t,
            >>>
            >>> RequestAbbrText Value,
            >>>
            >>> SendAbbrTextVal ue,
            >>>
            >>> ClearAbbrTextOn Client
            >>>
            >>> }
            >>>
            >>> public class Packet
            >>>
            >>> {
            >>>
            >>> private byte command;
            >>>
            >>> private int dataLength=0;
            >>>
            >>> private byte[] Data;
            >>>
            >>> public byte[] PacketData
            >>>
            >>> {
            >>>
            >>> get
            >>>
            >>> {
            >>>
            >>> return Data;
            >>>
            >>> }
            >>>
            >>> set
            >>>
            >>> {
            >>>
            >>> Data=value;
            >>>
            >>> dataLength=Data .Length;
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> public int Length
            >>>
            >>> {
            >>>
            >>> get
            >>>
            >>> {
            >>>
            >>> if (Data==null)
            >>>
            >>> return 5;
            >>>
            >>> else
            >>>
            >>> return dataLength+5;
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> public PacketType Command
            >>>
            >>> {
            >>>
            >>> get
            >>>
            >>> {
            >>>
            >>> return (PacketType)com mand;
            >>>
            >>> }
            >>>
            >>> set
            >>>
            >>> {
            >>>
            >>> command=(byte)v alue;
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> public string StrPacketData
            >>>
            >>> {
            >>>
            >>> get {return System.Text.Enc oding.ASCII.Get String(Data);}
            >>>
            >>> set
            >>>
            >>> {
            >>>
            >>> Data=System.Tex t.Encoding.ASCI I.GetBytes(valu e.ToCharArray() );
            >>>
            >>> dataLength=Data .Length;
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> public Packet()
            >>>
            >>> {
            >>>
            >>> Command=PacketT ype.IgnoreThisP acket;
            >>>
            >>> }
            >>>
            >>> public Packet(PacketTy pe cmd)
            >>>
            >>> {
            >>>
            >>> Command=cmd;
            >>>
            >>> }
            >>>
            >>> public Packet(byte[] thisdata)
            >>>
            >>> {
            >>>
            >>> if (thisdata.Lengt h>0)
            >>>
            >>> command=thisdat a[0];
            >>>
            >>> if (thisdata.Lengt h>5)
            >>>
            >>> {
            >>>
            >>> dataLength =
            >>>
            >>> (((int)thisdata[4]) << 24) +
            >>>
            >>> (((int)thisdata[3]) << 16) +
            >>>
            >>> (((int)thisdata[2]) << 8) +
            >>>
            >>> ((int)thisdata[1]);
            >>>
            >>> if (dataLength>0)
            >>>
            >>> {
            >>>
            >>> Data=new Byte[dataLength];
            >>>
            >>> Array.Copy(this data,5,Data,0,d ataLength);
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> public Packet(PacketTy pe cmd, byte[] thisdata)
            >>>
            >>> {
            >>>
            >>> Command=cmd;
            >>>
            >>> Data=thisdata;
            >>>
            >>> dataLength=Data .Length;
            >>>
            >>> }
            >>>
            >>> public Packet(PacketTy pe cmd, string thisdata)
            >>>
            >>> {
            >>>
            >>> Command=cmd;
            >>>
            >>> Data=System.Tex t.Encoding.ASCI I.GetBytes(this data.ToCharArra y());
            >>>
            >>> dataLength=Data .Length;
            >>>
            >>> Debug.WriteLine ("setting dataLength to "+dataLengt h);
            >>>
            >>> }
            >>>
            >>> public byte[] Serialize()
            >>>
            >>> {
            >>>
            >>> int len=this.Length ;
            >>>
            >>> byte[] tempcmd=new byte[len];
            >>>
            >>> tempcmd[0] = command;
            >>>
            >>> tempcmd[1] = (byte)(dataLeng th & 0xff);
            >>>
            >>> tempcmd[2] = (byte)((dataLen gth >> 8) & 0xff);
            >>>
            >>> tempcmd[3] = (byte)((dataLen gth >>16) & 0xff);
            >>>
            >>> tempcmd[4] = (byte)((dataLen gth >>24) & 0xff);
            >>>
            >>>
            >>> if (len>5)
            >>>
            >>> {
            >>>
            >>> Array.Copy(Data ,0,tempcmd,5,da taLength);
            >>>
            >>> }
            >>>
            >>> return tempcmd;
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>> }
            >>>
            >>>
            >>> "Gianmaria I." <nowaytoknow@ho thot.it> wrote in message
            >>> news:eZmzfxocFH A.3564@tk2msftn gp13.phx.gbl...
            >>>> Hi,
            >>>> having a BitArray, how can i extract bits to create a System.byte
            >>>>
            >>>> as in the example...
            >>>>
            >>>> With
            >>>> BitArray bits
            >>>> and
            >>>> Byte myNewByte
            >>>>
            >>>> bits[0] to bits[7] => myNewByte
            >>>>
            >>>>
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            Working...