Question:
I have a byte array with two values: 07
and DE
(in hex).
What I need to do is somehow concatenate the 07DE
and get the decimal value from that hex value. In this case, it is 2014
.
My code:
1 2 3 4 5 6 |
# 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] |
How do I combined these to make 07DE
and convert that to an int to get 2014
?
Answer:
Another option is to use the .NET System.BitConvert class:
1 2 3 4 |
C:\PS> $bytes = [byte[]](0xDE,0x07) C:\PS> [bitconverter]::ToInt16($bytes,0) 2014 |