C# BitConverter ToUInt64

Description

BitConverter ToUInt64 returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.

Syntax

BitConverter.ToUInt64 has the following syntax.


[CLSCompliantAttribute(false)]/*from   w w w  .java 2 s.  c  om*/
public static ulong ToUInt64(
  byte[] value,
  int startIndex
)

Parameters

BitConverter.ToUInt64 has the following parameters.

  • value - An array of bytes.
  • startIndex - The starting position within value.

Returns

BitConverter.ToUInt64 method returns A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.

Example

The following code example converts elements of Byte arrays to UInt64 values with the ToUInt64 method.


using System;//from w  ww .  j  a  v  a2s .co m

class BytesToUInt64Demo
{
    public static void Main( )
    {
        byte[ ] bytes = {
            255, 255, 255,   0,   0,   0,   0,   0,   0,   0, 
            170, 170, 170, 170, 170,   0,   0, 232, 137,   4, 
             35, 199, 138, 255, 255, 255, 255, 255, 255, 255, 
            255, 127 };

        ulong value = BitConverter.ToUInt64( bytes, 2 );

        Console.WriteLine(value );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version