Byte to integer in C#


SUBMITTED BY: menamagice

DATE: Aug. 9, 2017, 1:49 a.m.

FORMAT: ANTLR With C# Target

SIZE: 297 Bytes

HITS: 300

  1. byte[] bytes = { 0, 0, 0, 25 };
  2. // If the system architecture is little-endian (that is, little end first),
  3. // reverse the byte array.
  4. if (BitConverter.IsLittleEndian)
  5. Array.Reverse(bytes);
  6. int i = BitConverter.ToInt32(bytes, 0);
  7. Console.WriteLine("int: {0}", i);
  8. // Output: int: 25

comments powered by Disqus