Convert U Int To Byte Array - CSharp System

CSharp examples for System:Byte Array

Description

Convert U Int To Byte Array

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from w  ww  .ja  v a  2  s.c o  m*/

public class Main{
        public static byte[] ConvertUInt64ToByteArray(UInt64 input)
        {
            byte[] uInt64AsByteArray = BitConverter.GetBytes(input);
            Array.Reverse(uInt64AsByteArray);
            var i = 0;
            while (uInt64AsByteArray[i] == 0)
            {
                ++i;
            }
            byte[] result = new byte[uInt64AsByteArray.Length - i];
            Array.Copy(uInt64AsByteArray, i, result, 0, uInt64AsByteArray.Length - i);
            return result;
        }
}

Related Tutorials