Powershell 字节数组到 INT

Kid*_*mba 3 arrays powershell byte type-conversion

我有一个带有两个值的字节数组:07和DE(十六进制)。

我需要做的是以某种方式连接07DE并从该十六进制值中获取十进制值。在这种情况下,它是2014。

我的代码:

# This line gives 11 bytes worth of information
[Byte[]] $hexbyte2 = $obj.OIDValueB

# All I need are the first two bytes (the values in this case are 07 and DE in HEX)
[Byte[]] $year = $hexbyte2[0], $hexbyte2[1]
Run Code Online (Sandbox Code Playgroud)

我如何组合这些来制作07DE并将其转换为 int 以获取2014?

Kei*_*ill 6

另一种选择是使用 .NET System.BitConvert 类:

C:\PS> $bytes = [byte[]](0xDE,0x07)
C:\PS> [bitconverter]::ToInt16($bytes,0)
2014
Run Code Online (Sandbox Code Playgroud)