BitConverter.GetBytes Method (UInt64)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns the specified 64-bit unsigned integer value as an array of bytes.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.UInt64
The number to convert.
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 */
Show: