BitConverter Classe
Definição
Converte tipos de dados para uma matriz de bytes e uma matriz de bytes para tipos de dados base de base.Converts base data types to an array of bytes, and an array of bytes to base data types.
public ref class BitConverter abstract sealed
public ref class BitConverter sealed
public static class BitConverter
public sealed class BitConverter
type BitConverter = class
Public Class BitConverter
Public NotInheritable Class BitConverter
- Herança
-
BitConverter
Exemplos
O exemplo de código a seguir ilustra o uso de vários BitConverter métodos de classe.The following code example illustrates the use of several BitConverter class methods.
// Example of BitConverter class methods.
using namespace System;
int main()
{
String^ formatter = "{0,25}{1,30}";
double aDoubl = 0.1111111111111111111;
float aSingl = 0.1111111111111111111F;
__int64 aLong = 1111111111111111111;
int anInt = 1111111111;
short aShort = 11111;
__wchar_t aChar = L'*';
bool aBool = true;
Console::WriteLine( "This example of methods of the BitConverter class"
"\ngenerates the following output.\n" );
Console::WriteLine( formatter, "argument", "byte array" );
Console::WriteLine( formatter, "--------", "----------" );
// Convert values to Byte arrays and display them.
Console::WriteLine( formatter, aDoubl, BitConverter::ToString( BitConverter::GetBytes( aDoubl ) ) );
Console::WriteLine( formatter, aSingl, BitConverter::ToString( BitConverter::GetBytes( aSingl ) ) );
Console::WriteLine( formatter, aLong, BitConverter::ToString( BitConverter::GetBytes( aLong ) ) );
Console::WriteLine( formatter, anInt, BitConverter::ToString( BitConverter::GetBytes( anInt ) ) );
Console::WriteLine( formatter, aShort, BitConverter::ToString( BitConverter::GetBytes( aShort ) ) );
Console::WriteLine( formatter, aChar, BitConverter::ToString( BitConverter::GetBytes( aChar ) ) );
Console::WriteLine( formatter, aBool, BitConverter::ToString( BitConverter::GetBytes( aBool ) ) );
}
/*
This example of methods of the BitConverter class
generates the following output.
argument byte array
-------- ----------
0.111111111111111 1C-C7-71-1C-C7-71-BC-3F
0.1111111 39-8E-E3-3D
1111111111111111111 C7-71-C4-2B-AB-75-6B-0F
1111111111 C7-35-3A-42
11111 67-2B
* 2A-00
True 01
*/
// Example of BitConverter class methods.
using System;
class BitConverterDemo
{
public static void Main( )
{
const string formatter = "{0,25}{1,30}";
double aDoubl = 0.1111111111111111111;
float aSingl = 0.1111111111111111111F;
long aLong = 1111111111111111111;
int anInt = 1111111111;
short aShort = 11111;
char aChar = '*';
bool aBool = true;
Console.WriteLine(
"This example of methods of the BitConverter class" +
"\ngenerates the following output.\n" );
Console.WriteLine( formatter, "argument", "byte array" );
Console.WriteLine( formatter, "--------", "----------" );
// Convert values to Byte arrays and display them.
Console.WriteLine( formatter, aDoubl,
BitConverter.ToString( BitConverter.GetBytes( aDoubl ) ) );
Console.WriteLine( formatter, aSingl,
BitConverter.ToString( BitConverter.GetBytes( aSingl ) ) );
Console.WriteLine( formatter, aLong,
BitConverter.ToString( BitConverter.GetBytes( aLong ) ) );
Console.WriteLine( formatter, anInt,
BitConverter.ToString( BitConverter.GetBytes( anInt ) ) );
Console.WriteLine( formatter, aShort,
BitConverter.ToString( BitConverter.GetBytes( aShort ) ) );
Console.WriteLine( formatter, aChar,
BitConverter.ToString( BitConverter.GetBytes( aChar ) ) );
Console.WriteLine( formatter, aBool,
BitConverter.ToString( BitConverter.GetBytes( aBool ) ) );
}
}
/*
This example of methods of the BitConverter class
generates the following output.
argument byte array
-------- ----------
0.111111111111111 1C-C7-71-1C-C7-71-BC-3F
0.1111111 39-8E-E3-3D
1111111111111111111 C7-71-C4-2B-AB-75-6B-0F
1111111111 C7-35-3A-42
11111 67-2B
* 2A-00
True 01
*/
' Example of BitConverter class methods.
Module BitConverterDemo
Sub Main( )
Const formatter As String = "{0,25}{1,30}"
Dim aDoubl As Double = 0.1111111111111111111
Dim aSingl As Single = 0.1111111111111111111
Dim aLong As Long = 1111111111111111111
Dim anInt As Integer = 1111111111
Dim aShort As Short = 11111
Dim aChar As Char = "*"c
Dim aBool As Boolean = True
Console.WriteLine( _
"This example of methods of the BitConverter class" & _
vbCrLf & "generates the following output." & vbCrLf )
Console.WriteLine( formatter, "argument", "Byte array" )
Console.WriteLine( formatter, "--------", "----------" )
' Convert values to Byte arrays and display them.
Console.WriteLine( formatter, aDoubl, _
BitConverter.ToString( BitConverter.GetBytes( aDoubl ) ) )
Console.WriteLine( formatter, aSingl, _
BitConverter.ToString( BitConverter.GetBytes( aSingl ) ) )
Console.WriteLine( formatter, aLong, _
BitConverter.ToString( BitConverter.GetBytes( aLong ) ) )
Console.WriteLine( formatter, anInt, _
BitConverter.ToString( BitConverter.GetBytes( anInt ) ) )
Console.WriteLine( formatter, aShort, _
BitConverter.ToString( BitConverter.GetBytes( aShort ) ) )
Console.WriteLine( formatter, aChar, _
BitConverter.ToString( BitConverter.GetBytes( aChar ) ) )
Console.WriteLine( formatter, aBool, _
BitConverter.ToString( BitConverter.GetBytes( aBool ) ) )
End Sub
End Module
' This example of methods of the BitConverter class
' generates the following output.
'
' argument Byte array
' -------- ----------
' 0.111111111111111 1C-C7-71-1C-C7-71-BC-3F
' 0.1111111 39-8E-E3-3D
' 1111111111111111111 C7-71-C4-2B-AB-75-6B-0F
' 1111111111 C7-35-3A-42
' 11111 67-2B
' * 2A-00
' True 01
Comentários
A BitConverter classe ajuda a manipular tipos de valor em sua forma fundamental, como uma série de bytes.The BitConverter class helps manipulate value types in their fundamental form, as a series of bytes. Um byte é definido como um inteiro sem sinal de 8 bits.A byte is defined as an 8-bit unsigned integer. A BitConverter classe inclui métodos estáticos para converter cada um dos tipos primitivos de e para uma matriz de bytes, como ilustra a tabela a seguir.The BitConverter class includes static methods to convert each of the primitive types to and from an array of bytes, as the following table illustrates.
TipoType | Para conversão de bytesTo byte conversion | Conversão de byteFrom byte conversion |
---|---|---|
Boolean | GetBytes(Boolean) | ToBoolean |
Char | GetBytes(Char) | ToChar |
Double | GetBytes(Double) - ou --or- DoubleToInt64Bits(Double) |
ToDouble - ou --or- Int64BitsToDouble |
Int16 | GetBytes(Int16) | ToInt16 |
Int32 | GetBytes(Int32) | ToInt32 |
Int64 | GetBytes(Int64) | ToInt64 |
Single | GetBytes(Single) | ToSingle |
UInt16 | GetBytes(UInt16) | ToUInt16 |
UInt32 | GetBytes(UInt32) | ToUInt32 |
UInt64 | GetBytes(UInt64) | ToUInt64 |
Se você usar BitConverter métodos para dados de viagem de ida e volta, certifique-se de que a GetBytes sobrecarga e o método de To
tipo especifiquem o mesmo tipo.If you use BitConverter methods to round-trip data, make sure that the GetBytes overload and the To
Type method specify the same type. Como o exemplo a seguir ilustra, a restauração de uma matriz que representa um inteiro assinado chamando o ToUInt32 método pode resultar em um valor diferente do original.As the following example illustrates, restoring an array that represents a signed integer by calling the ToUInt32 method can result in a value that is different from the original. Para obter mais informações, consulte a entrada trabalhando com valores de não decimais e bitais assinados no blog da equipe da BCL.For more information, see the entry Working with Signed Non-Decimal and Bitwise Values in the BCL Team Blog.
using System;
public class Example
{
public static void Main()
{
int value = -16;
Byte[] bytes = BitConverter.GetBytes(value);
// Convert bytes back to Int32.
int intValue = BitConverter.ToInt32(bytes, 0);
Console.WriteLine("{0} = {1}: {2}",
value, intValue,
value.Equals(intValue) ? "Round-trips" : "Does not round-trip");
// Convert bytes to UInt32.
uint uintValue = BitConverter.ToUInt32(bytes, 0);
Console.WriteLine("{0} = {1}: {2}", value, uintValue,
value.Equals(uintValue) ? "Round-trips" : "Does not round-trip");
}
}
// The example displays the following output:
// -16 = -16: Round-trips
// -16 = 4294967280: Does not round-trip
Module Example
Public Sub Main()
Dim value As Integer = -16
Dim bytes() As Byte = BitConverter.GetBytes(value)
' Convert bytes back to Int32.
Dim intValue As Integer = BitConverter.ToInt32(bytes, 0)
Console.WriteLine("{0} = {1}: {2}",
value, intValue,
If(value.Equals(intValue), "Round-trips", "Does not round-trip"))
' Convert bytes to UInt32.
Dim uintValue As UInteger = BitConverter.ToUInt32(bytes, 0)
Console.WriteLine("{0} = {1}: {2}", value, uintValue,
If(value.Equals(uintValue), "Round-trips", "Does not round-trip"))
End Sub
End Module
' The example displays the following output:
' -16 = -16: Round-trips
' -16 = 4294967280: Does not round-trip
A ordem dos bytes na matriz retornada pelo método é GetBytes sobrecarregado (bem como a ordem de bits no inteiro retornado pelo DoubleToInt64Bits método e a ordem das cadeias de caracteres hexadecimais retornada pelo ToString(Byte[]) método) depende se a arquitetura do computador é little-endian ou big-endian.The order of bytes in the array returned by the GetBytes method overloads (as well as the order of bits in the integer returned by the DoubleToInt64Bits method and the order of hexadecimal strings returned by the ToString(Byte[]) method) depends on whether the computer architecture is little-endian or big-endian. Da mesma forma, a ordem dos bytes na matriz e retornada pelos To
métodos integerValue e o ToChar método depende se a arquitetura do computador é little-endian ou big-endian.Similarly, the order of bytes in the array and returned by the To
IntegerValue methods and the ToChar method depends on whether the computer architecture is little-endian or big-endian. A endian de uma arquitetura é indicada pela IsLittleEndian propriedade, que retorna true
em sistemas pequenos endian e false
em sistemas big endian.The endianness of an architecture is indicated by the IsLittleEndian property, which returns true
on little-endian systems and false
on big-endian systems. Em sistemas pequenos endian, os bytes de ordem inferior precedem bytes de ordem superior.On little-endian systems, lower-order bytes precede higher-order bytes. Em um sistema big endian, os bytes de ordem superior precedem os bytes de ordem inferior.On big-endian system, higher-order bytes precede lower-order bytes. A tabela a seguir ilustra a diferença nas matrizes de bytes que resultam da passagem do inteiro 1.234.567.890 (0x499602D2) para o GetBytes(Int32) método.The following table illustrates the difference in the byte arrays that result from passing the integer 1,234,567,890 (0x499602D2) to the GetBytes(Int32) method. Os bytes são listados na ordem do byte no índice 0 para o byte no índice 3.The bytes are listed in order from the byte at index 0 to the byte at index 3.
Little-endianLittle-endian | D2-02-96-49D2-02-96-49 |
Big endianBig-endian | 49-96-02-D249-96-02-D2 |
Como o valor de retorno de alguns métodos depende da arquitetura do sistema, tenha cuidado ao transmitir dados de byte além dos limites da máquina:Because the return value of some methods depends on system architecture, be careful when transmitting byte data beyond machine boundaries:
Se todos os sistemas que enviam e recebem dados estão garantidos têm a mesma endian, nada é feito com os dados.If all systems sending and receiving data are guaranteed to have the same endianness, nothing has be done to the data.
Se os sistemas que enviam e recebem dados podem ter uma endian diferente, sempre transmita dados em uma ordem específica.If systems sending and receiving data can have different endianness, always transmit data in a particular order. Isso significa que a ordem de bytes na matriz pode ter que ser revertida antes de enviá-los ou depois de recebê-los.This means that the order of bytes in the array may have to be reversed either before sending them or after receiving them. Uma convenção comum é transmitir dados em ordem de bytes de rede (ordem big-endian).A common convention is to transmit data in network byte order (big-endian order). O exemplo a seguir fornece uma implementação para enviar um valor inteiro na ordem de bytes de rede.The following example provides an implementation for sending an integer value in network byte order.
using System; public class Example { public static void Main() { int value = 12345678; byte[] bytes = BitConverter.GetBytes(value); Console.WriteLine(BitConverter.ToString(bytes)); if (BitConverter.IsLittleEndian) Array.Reverse(bytes); Console.WriteLine(BitConverter.ToString(bytes)); // Call method to send byte stream across machine boundaries. // Receive byte stream from beyond machine boundaries. Console.WriteLine(BitConverter.ToString(bytes)); if (BitConverter.IsLittleEndian) Array.Reverse(bytes); Console.WriteLine(BitConverter.ToString(bytes)); int result = BitConverter.ToInt32(bytes, 0); Console.WriteLine("Original value: {0}", value); Console.WriteLine("Returned value: {0}", result); } } // The example displays the following output on a little-endian system: // 4E-61-BC-00 // 00-BC-61-4E // 00-BC-61-4E // 4E-61-BC-00 // Original value: 12345678 // Returned value: 12345678
Module Example Public Sub Main() Dim value As Integer = 12345678 Dim bytes() As Byte = BitConverter.GetBytes(value) Console.WriteLine(BitConverter.ToString(bytes)) If BitConverter.IsLittleEndian Then Array.Reverse(bytes) End If Console.WriteLine(BitConverter.ToString(bytes)) ' Call method to send byte stream across machine boundaries. ' Receive byte stream from beyond machine boundaries. Console.WriteLine(BitConverter.ToString(bytes)) If BitConverter.IsLittleEndian Then Array.Reverse(bytes) End If Console.WriteLine(BitConverter.ToString(bytes)) Dim result As Integer = BitConverter.ToInt32(bytes, 0) Console.WriteLine("Original value: {0}", value) Console.WriteLine("Returned value: {0}", result) End Sub End Module ' The example displays the following output on a little-endian system: ' 4E-61-BC-00 ' 00-BC-61-4E ' 00-BC-61-4E ' 4E-61-BC-00 ' Original value: 12345678 ' Returned value: 12345678
Se os sistemas que enviam e recebem dados podem ter uma endian diferente e os dados a serem transmitidos consistem em inteiros assinados, chame o IPAddress.HostToNetworkOrder método para converter os dados em ordem de bytes de rede e o IPAddress.NetworkToHostOrder método para convertê-los na ordem exigida pelo destinatário.If systems sending and receiving data can have different endianness and the data to be transmitted consists of signed integers, call the IPAddress.HostToNetworkOrder method to convert the data to network byte order and the IPAddress.NetworkToHostOrder method to convert it to the order required by the recipient.
Campos
IsLittleEndian |
Indica a ordem de byte (“endianness”) na qual os dados são armazenados nessa arquitetura de computador.Indicates the byte order ("endianness") in which data is stored in this computer architecture. |
Métodos
DoubleToInt64Bits(Double) |
Converte o número de ponto flutuante de precisão dupla especificado em um inteiro com sinal de 64 bits.Converts the specified double-precision floating point number to a 64-bit signed integer. |
GetBytes(Boolean) |
Retorna o valor booliano especificado como uma matriz de bytes.Returns the specified Boolean value as a byte array. |
GetBytes(Char) |
Retorna o valor de caractere Unicode especificado como uma matriz de bytes.Returns the specified Unicode character value as an array of bytes. |
GetBytes(Double) |
Retorna o valor especificado do ponto flutuante de dupla precisão como uma matriz de bytes.Returns the specified double-precision floating point value as an array of bytes. |
GetBytes(Int16) |
Retorna o valor inteiro com sinal de 16 bits especificado como uma matriz de bytes.Returns the specified 16-bit signed integer value as an array of bytes. |
GetBytes(Int32) |
Retorna o valor inteiro com sinal de 32 bits especificado como uma matriz de bytes.Returns the specified 32-bit signed integer value as an array of bytes. |
GetBytes(Int64) |
Retorna o valor inteiro com sinal de 64 bits especificado como uma matriz de bytes.Returns the specified 64-bit signed integer value as an array of bytes. |
GetBytes(Single) |
Retorna o valor especificado do ponto flutuante de precisão simples como uma matriz de bytes.Returns the specified single-precision floating point value as an array of bytes. |
GetBytes(UInt16) |
Retorna o valor do inteiro sem sinal de 16 bits especificado como uma matriz de bytes.Returns the specified 16-bit unsigned integer value as an array of bytes. |
GetBytes(UInt32) |
Retorna o valor do inteiro sem sinal de 32 bits especificado como uma matriz de bytes.Returns the specified 32-bit unsigned integer value as an array of bytes. |
GetBytes(UInt64) |
Retorna o valor do inteiro sem sinal de 64 bits especificado como uma matriz de bytes.Returns the specified 64-bit unsigned integer value as an array of bytes. |
Int32BitsToSingle(Int32) |
Reinterpreta o inteiro de 32 bits especificado como um valor de ponto flutuante de precisão simples.Reinterprets the specified 32-bit integer as a single-precision floating-point value. |
Int64BitsToDouble(Int64) |
Reinterpreta o inteiro com sinal de 64 bits especificado em um número de ponto flutuante de precisão dupla.Reinterprets the specified 64-bit signed integer to a double-precision floating point number. |
SingleToInt32Bits(Single) |
Converte um valor de ponto flutuante de precisão simples em um inteiro.Converts a single-precision floating-point value into an integer. |
ToBoolean(Byte[], Int32) |
Retorna um valor booliano convertido do byte em uma posição especificada em uma matriz de bytes.Returns a Boolean value converted from the byte at a specified position in a byte array. |
ToBoolean(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um valor booliano.Converts a read-only byte span to a Boolean value. |
ToChar(Byte[], Int32) |
Retorna um caractere Unicode convertido dos dois bytes em uma posição especificada em uma matriz de bytes.Returns a Unicode character converted from two bytes at a specified position in a byte array. |
ToChar(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um caractere.Converts a read-only byte span into a character. |
ToDouble(Byte[], Int32) |
Retorna um número de ponto flutuante de precisão dupla convertido de oito bytes em uma posição especificada em uma matriz de bytes.Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. |
ToDouble(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um valor de ponto flutuante de precisão dupla.Converts a read-only byte span into a double-precision floating-point value. |
ToInt16(Byte[], Int32) |
Retorna um inteiro com sinal de 16 bits convertido de dois bytes em uma posição especificada em uma matriz de bytes.Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. |
ToInt16(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um inteiro com sinal de 16 bits.Converts a read-only byte span into a 16-bit signed integer. |
ToInt32(Byte[], Int32) |
Retorna um inteiro com sinal de 32 bits convertido de quatro bytes em uma posição especificada em uma matriz de bytes.Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. |
ToInt32(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um inteiro com sinal de 32 bits.Converts a read-only byte span into a 32-bit signed integer. |
ToInt64(Byte[], Int32) |
Retorna um inteiro com sinal de 64 bits convertido de oito bytes em uma posição especificada em uma matriz de bytes.Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. |
ToInt64(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um inteiro com sinal de 64 bits.Converts a read-only byte span into a 64-bit signed integer. |
ToSingle(Byte[], Int32) |
Retorna um número de ponto flutuante de precisão simples convertido de quatro bytes em uma posição especificada em uma matriz de bytes.Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. |
ToSingle(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um valor de ponto flutuante de precisão dupla.Converts a read-only byte span into a double-precision floating-point value. |
ToString(Byte[]) |
Converte o valor numérico de cada elemento de uma matriz de bytes especificada em sua representação de cadeia de caracteres hexadecimal equivalente.Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. |
ToString(Byte[], Int32) |
Converte o valor numérico de cada elemento de uma submatriz de bytes especificada em sua representação de cadeia de caracteres hexadecimal equivalente.Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. |
ToString(Byte[], Int32, Int32) |
Converte o valor numérico de cada elemento de uma submatriz de bytes especificada em sua representação de cadeia de caracteres hexadecimal equivalente.Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. |
ToUInt16(Byte[], Int32) |
Retorna um inteiro sem sinal de 16 bits convertido de dois bytes em uma posição especificada em uma matriz de bytes.Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. |
ToUInt16(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um inteiro sem sinal de 16 bits.Converts a read-only byte-span into a 16-bit unsigned integer. |
ToUInt32(Byte[], Int32) |
Retorna um inteiro sem sinal de 32 bits convertido de quatro bytes em uma posição especificada em uma matriz de bytes.Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. |
ToUInt32(ReadOnlySpan<Byte>) |
Converte um intervalo de bytes somente leitura em um inteiro sem sinal de 32 bits.Converts a read-only byte span into a 32-bit unsigned integer. |
ToUInt64(Byte[], Int32) |
Retorna um inteiro sem sinal de 64 bits convertido de oito bytes em uma posição especificada em uma matriz de bytes.Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. |
ToUInt64(ReadOnlySpan<Byte>) |
Converte bytes em um unsigned long.Converts bytes into an unsigned long. |
TryWriteBytes(Span<Byte>, Boolean) |
Converte um booliano em um intervalo de bytes.Converts a Boolean into a span of bytes. |
TryWriteBytes(Span<Byte>, Char) |
Converte um caractere em um intervalo de bytes.Converts a character into a span of bytes. |
TryWriteBytes(Span<Byte>, Double) |
Converte um valor de ponto flutuante de precisão dupla em um intervalo de bytes.Converts a double-precision floating-point value into a span of bytes. |
TryWriteBytes(Span<Byte>, Int16) |
Converte um inteiro com sinal de 16 bits em um intervalo de bytes.Converts a 16-bit signed integer into a span of bytes. |
TryWriteBytes(Span<Byte>, Int32) |
Converte um inteiro com sinal de 32 bits em um intervalo de bytes.Converts a 32-bit signed integer into a span of bytes. |
TryWriteBytes(Span<Byte>, Int64) |
Converte um inteiro com sinal de 64 bits em um intervalo de bytes.Converts a 64-bit signed integer into a span of bytes. |
TryWriteBytes(Span<Byte>, Single) |
Converte um valor de ponto flutuante de precisão dupla em um intervalo de bytes.Converts a double-precision floating-point value into a span of bytes. |
TryWriteBytes(Span<Byte>, UInt16) |
Converte um inteiro sem sinal de 16 bits em um intervalo de bytes.Converts an unsigned 16-bit integer into a span of bytes. |
TryWriteBytes(Span<Byte>, UInt32) |
Converte um inteiro sem sinal de 32 bits em um intervalo de bytes.Converts a 32-bit unsigned integer into a span of bytes. |
TryWriteBytes(Span<Byte>, UInt64) |
Converte um inteiro sem sinal de 64 bits em um intervalo de bytes.Converts an unsigned 64-bit integer into a span of bytes. |