1: public static int BytesToInt(byte[] bytes)
   2: {
   3:     return int.Parse(BytesToString(bytes).Trim());
   4: }
   5:  
   6: public static string BytesToString(byte[] bytes)
   7: {
   8:     ASCIIEncoding enc = new System.Text.ASCIIEncoding();
   9:     return enc.GetString(bytes);
  10: }

   1: public static byte[] IntToBytes(int value)
   2: {
   3:     ASCIIEncoding enc = new System.Text.ASCIIEncoding();
   4:     return enc.GetBytes(value.ToString());
   5: }

Code Snippet
  1.         /// <summary>
  2.         /// Bytes to Integer
  3.         /// </summary>
  4.         /// <param name=”src”></param>
  5.         /// <returns></returns>
  6.         public static int BytesToInt(byte[] src)
  7.         {
  8.             if (src.Length == 1)
  9.                 return (int)src[0];
  10.             else if (src.Length <= 2)
  11.                 return BitConverter.ToInt16(src, 0);
  12.             return BitConverter.ToInt32(src, 0);
  13.         }