Search notes:

System.BitConverter (class)

System.BitConverter allows to convert base types to byte arrays and vice versa.
The method GetBytes(val) is overloaded for various base types and returns the base type's internal byte representation with which it stores val.
The methods ToX(byteArray) convert byteArray to the base type X (for example ToInt32()).

PowerShell example

The following PowerShell example converts an Int32 to a byte array:
[int32]  $int_32 = 4100

[byte[]] $bytes  = [System.BitConverter]::GetBytes($int_32)

$bytes -join ', '
#
#  4, 16, 0, 0
Github repository .NET-API, path: /System/BitConverter/X-to-bytes.ps1

See also

The ToX methods in System.Convert that convert certain values to intergral numeric types.

Index