BitConverter.GetBytes Method (UInt64)

Returns the specified 64-bit unsigned integer value as an array of bytes.

This API is not CLS-compliant. 

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static byte[] GetBytes(
	ulong value


Type: System.UInt64
The number to convert.

Return Value

Type: System.Byte[]
An array of bytes with length 8.

The following code example converts the bit patterns of UInt64 values to Byte arrays with the GetBytes method.

// Example of the BitConverter.GetBytes( ulong ) method.
using System;

class Example
   const string formatter = "{0,22}{1,30}";

   // Convert a ulong argument to a byte array and display it.
   public static void GetBytesUInt64(System.Windows.Controls.TextBlock outputBlock, ulong argument)
      byte[] byteArray = BitConverter.GetBytes(argument);
      outputBlock.Text += String.Format(formatter, argument,
          BitConverter.ToString(byteArray)) + "\n";

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      outputBlock.Text += String.Format(
          "This example of the BitConverter.GetBytes( ulong ) " +
          "\nmethod generates the following output.\n") + "\n";
      outputBlock.Text += String.Format(formatter, "ulong", "byte array") + "\n";
      outputBlock.Text += String.Format(formatter, "-----", "----------") + "\n";

      // Convert ulong values and display the results.
      GetBytesUInt64(outputBlock, 0xFFFFFF);
      GetBytesUInt64(outputBlock, 1000000000);
      GetBytesUInt64(outputBlock, 0x100000000);
      GetBytesUInt64(outputBlock, 0xAAAAAAAAAAAA);
      GetBytesUInt64(outputBlock, 1000000000000000000);
      GetBytesUInt64(outputBlock, 10000000000000000000);
      GetBytesUInt64(outputBlock, ulong.MinValue);
      GetBytesUInt64(outputBlock, long.MaxValue);
      GetBytesUInt64(outputBlock, ulong.MaxValue);

This example of the BitConverter.GetBytes( ulong )
method generates the following output.

                 ulong                    byte array
                 -----                    ----------
              16777215       FF-FF-FF-00-00-00-00-00
            1000000000       00-CA-9A-3B-00-00-00-00
            4294967296       00-00-00-00-01-00-00-00
       187649984473770       AA-AA-AA-AA-AA-AA-00-00
   1000000000000000000       00-00-64-A7-B3-B6-E0-0D
  10000000000000000000       00-00-E8-89-04-23-C7-8A
                     0       00-00-00-00-00-00-00-00
   9223372036854775807       FF-FF-FF-FF-FF-FF-FF-7F
  18446744073709551615       FF-FF-FF-FF-FF-FF-FF-FF


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions