BitConverter in C# provides a convenient way to: convert int to byte array or assemble int from a byte sequence. Of course, you can write your own routine to do all the work, but it’s good to know .net already have this built in. Please check out my test routine for an example:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int testValue = 8;
byte[] buffer = BitConverter.GetBytes(testValue);
int convertBack = BitConverter.ToInt32(buffer, 0);
Console.WriteLine("Test value : {0}", testValue);
Console.WriteLine("Convert to byte array: {0}", BitConverter.ToString(buffer));
Console.WriteLine("Convert to int from byte array: {0}", convertBack);
}
}
}

Besides int, this could apply to all the basic built in types: float, double, int64. Also one nice thing, it could print out an byte array easily like this:
BitConverter.ToString(buffer)
Also, .net has built in the routines to convert between host and network byte order (big endian):
IpAddress.NetworkToHostOrder
it supports: int16, int32, int64. You can build your own routine to do this, but if you know this, would definitely save your from some work.








