Get-Ryan

[Powershell] Convert-HexToByteArray

Feb 1st, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Convert-HexToByteArray {
  2.  
  3.     [cmdletbinding()]
  4.  
  5.     param(
  6.         [parameter(Mandatory=$true)]
  7.         [String]
  8.         $HexString
  9.     )
  10.  
  11.     $Bytes = [byte[]]::new($HexString.Length / 2)
  12.  
  13.     For($i=0; $i -lt $HexString.Length; $i+=2){
  14.         $Bytes[$i/2] = [convert]::ToByte($HexString.Substring($i, 2), 16)
  15.     }
  16.  
  17.     $Bytes
  18. }
Advertisement
Add Comment
Please, Sign In to add comment