How to

convert a byte array to an integer

Published: 13. December 2008 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: Converting » Numbers
Tags: C# Conversion
Was this snippet helpful for you? YESYES / NONO
byte[] bytesArray = { 0, 0, 1, 0 };

if (BitConverter.IsLittleEndian)
{
    Array.Reverse(bytesArray);
}

int number = BitConverter.ToInt32(bytesArray, 0);

Console.WriteLine(number);
Console Output:
256
Send us feedback about this snippet »



Related Snippets: