Convert byte array to a integer. - CSharp System

CSharp examples for System:Byte Array

Description

Convert byte array to a integer.

Demo Code


using Microsoft.Win32;
using System.Text;
using System.IO;/*from  w w w . ja v a2 s  . co m*/
using System;

public class Main{
        /// <summary>
        /// Convert byte array to a <see cref="long"/> integer.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static long BytesToLong(byte[] bytes)
        {
            long tempInt = 0;
            for(int i=0; i<bytes.Length; i++)
            {
                tempInt = tempInt<<8 | bytes[i];
            }
            return tempInt;
        }
}

Related Tutorials