Returns the specified 64-bit signed integer value as an array of bytes.
public:
static cli::array <System::Byte> ^ GetBytes(long value);
public static byte[] GetBytes(long value);
static member GetBytes : int64 -> byte[]
Public Shared Function GetBytes (value As Long) As Byte()
Parameters
The number to convert.
ReturnsAn array of bytes with length 8.
ExamplesThe following example calls the GetBytes method to convert each element in an Int64 array to a Byte arrays.
using System;
class Example
{
public static void Main()
{
// Define an array of Int64 values.
long[] values = { 0, 0xFFFFFF, -0xFFFFFF, 1000000000, -1000000000,
0x100000000, -0x100000000, 0xAAAAAAAAAAAA,
-0xAAAAAAAAAAAA, 1000000000000000000,
-1000000000000000000, long.MinValue,
long.MaxValue };
Console.WriteLine( "{0,22}{1,10} {2,30}", "Int64", "Endian", "Byte Array");
Console.WriteLine( "{0,22}{1,10} {2,30}", "----", "------", "----------" );
foreach (var value in values) {
// Convert each Int64 value to a byte array.
byte[] byteArray = BitConverter.GetBytes(value);
// Display the result.
Console.WriteLine("{0,22}{1,10}{2,30}", value,
BitConverter.IsLittleEndian ? "Little" : "Big",
BitConverter.ToString(byteArray));
}
}
}
// The example displays output like the following:
// Int64 Endian Byte Array
// ---- ------ ----------
// 0 Little 00-00-00-00-00-00-00-00
// 16777215 Little FF-FF-FF-00-00-00-00-00
// -16777215 Little 01-00-00-FF-FF-FF-FF-FF
// 1000000000 Little 00-CA-9A-3B-00-00-00-00
// -1000000000 Little 00-36-65-C4-FF-FF-FF-FF
// 4294967296 Little 00-00-00-00-01-00-00-00
// -4294967296 Little 00-00-00-00-FF-FF-FF-FF
// 187649984473770 Little AA-AA-AA-AA-AA-AA-00-00
// -187649984473770 Little 56-55-55-55-55-55-FF-FF
// 1000000000000000000 Little 00-00-64-A7-B3-B6-E0-0D
// -1000000000000000000 Little 00-00-9C-58-4C-49-1F-F2
// -9223372036854775808 Little 00-00-00-00-00-00-00-80
// 9223372036854775807 Little FF-FF-FF-FF-FF-FF-FF-7F
open System
// Define a list of Int64 values.
let values =
[ 0L; 0xFFFFFFL; -0xFFFFFFL; 1000000000L; -1000000000L
0x100000000L; -0x100000000L; 0xAAAAAAAAAAAAL
-0xAAAAAAAAAAAAL; 1000000000000000000L
-1000000000000000000L; Int64.MinValue; Int64.MaxValue ]
printfn "%22s%10s %30s" "Int64" "Endian" "Byte Array"
printfn "%22s%10s %30s" "----" "------" "----------"
for value in values do
// Convert each Int64 value to a byte array.
let byteArray = BitConverter.GetBytes value
// Display the result.
printfn $"""%22i{value}%10s{if BitConverter.IsLittleEndian then "Little" else "Big"} %30s{BitConverter.ToString byteArray}"""
// The example displays output like the following:
// Int64 Endian Byte Array
// ---- ------ ----------
// 0 Little 00-00-00-00-00-00-00-00
// 16777215 Little FF-FF-FF-00-00-00-00-00
// -16777215 Little 01-00-00-FF-FF-FF-FF-FF
// 1000000000 Little 00-CA-9A-3B-00-00-00-00
// -1000000000 Little 00-36-65-C4-FF-FF-FF-FF
// 4294967296 Little 00-00-00-00-01-00-00-00
// -4294967296 Little 00-00-00-00-FF-FF-FF-FF
// 187649984473770 Little AA-AA-AA-AA-AA-AA-00-00
// -187649984473770 Little 56-55-55-55-55-55-FF-FF
// 1000000000000000000 Little 00-00-64-A7-B3-B6-E0-0D
// -1000000000000000000 Little 00-00-9C-58-4C-49-1F-F2
// -9223372036854775808 Little 00-00-00-00-00-00-00-80
// 9223372036854775807 Little FF-FF-FF-FF-FF-FF-FF-7F
Public Module Example
Public Sub Main()
' Define an array of Int64 values.
Dim values() As Long = { 0, &hFFFFFF, -&hFFFFFF, 1000000000, -1000000000,
&h100000000, -&h100000000, &hAAAAAAAAAAAA,
-&hAAAAAAAAAAAA, 1000000000000000000,
-1000000000000000000, Long.MinValue,
Long.MaxValue }
Console.WriteLine( "{0,22}{1,10}{2,30}", "Int64", "Endian", "Byte Array" )
Console.WriteLine( "{0,22}{1,10}{2,30}", "----", "------", "----------" )
For Each value in values
' Convert each Int64 value to a byte array.
Dim byteArray() As Byte = BitConverter.GetBytes(value)
' Display the result.
Console.WriteLine("{0,22}{1,10}{2,30}", value,
If(BitConverter.IsLittleEndian, "Little", "Big"),
BitConverter.ToString(byteArray))
Next
End Sub
End Module
' The example displays the following output:
' Int64 Endian Byte Array
' ---- ------ ----------
' 0 Little 00-00-00-00-00-00-00-00
' 16777215 Little FF-FF-FF-00-00-00-00-00
' -16777215 Little 01-00-00-FF-FF-FF-FF-FF
' 1000000000 Little 00-CA-9A-3B-00-00-00-00
' -1000000000 Little 00-36-65-C4-FF-FF-FF-FF
' 4294967296 Little 00-00-00-00-01-00-00-00
' -4294967296 Little 00-00-00-00-FF-FF-FF-FF
' 187649984473770 Little AA-AA-AA-AA-AA-AA-00-00
' -187649984473770 Little 56-55-55-55-55-55-FF-FF
' 1000000000000000000 Little 00-00-64-A7-B3-B6-E0-0D
' -1000000000000000000 Little 00-00-9C-58-4C-49-1F-F2
' -9223372036854775808 Little 00-00-00-00-00-00-00-80
' 9223372036854775807 Little FF-FF-FF-FF-FF-FF-FF-7F
Remarks
The order of bytes in the array returned by the GetBytes method depends on whether the computer architecture is little-endian or big-endian.
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4