convert integer to byte array

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 1191
using System;

using System.IO;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

//Declare an integer variable and assign an integer value

Int32 intValue = 245;

Console.WriteLine("Integer Value: " + intValue .ToString());

//Convert integer value to byte array and display it

byte[] bytes = BitConverter.GetBytes(intValue );

Console.WriteLine("Byte Array Value: " + BitConverter.ToString(bytes));

//Convert and display the byte array back to integer

double doubleValue = BitConverter.ToInt32(bytes,0);

Console.WriteLine("Byte array back to Integer: " + doubleValue.ToString());

Console.ReadLine();
}
}
}

Comments or Responses

Login to post response