Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Have byte array, need to convert values to uint16, uint32

$
0
0

Howdy all,

I know I'm just being dense, but how do you convert specific bytes in an array to Uint16 or Uint32 variables?  I'm trying to do this with powershell.

I have a binary file that has some integer values imbedded into it at various offsets.  I can get the file into a byte array easily enough, but how do I extract a pair of bytes from it and convert that to a UInt16 value?  Additionally how about taking a UInt16 and making it back into a pair of bytes (even better: at a specific offset into an byte array)?

[Byte[]] $AByteArray = 0x0f, 0x00, 0x0e, 0x00

I'd like to read/convert bytes @ offset 2 & 3 into a UInt16 variable.

Clearly I need to worry about Endian-ness so 0x0e,0x00 is the integer value of 14

I'm considering a binary reader type of thing but seems like the [Byte].toUInt16 methods would do if I could figure out how to use them.

-greg


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>