c# convert int to byte code example
Example: c# number to byte
public byte[] ConvertNumToByte(int Number)
{
byte[] ByteArray = new byte[32];
string BinString = Convert.ToString(Number, 2);
char[] BinCharArray = BinString.ToCharArray();
try
{
System.Array.Reverse(BinCharArray);
if (BinCharArray != null && BinCharArray.Length > 0)
{
for (int index = 0; index < BinCharArray.Length; ++index)
{
ByteArray[index] = Convert.ToByte(Convert.ToString(BinCharArray[index]));
}
}
}
catch
{
}
return ByteArray;
}