Skip to content

Instantly share code, notes, and snippets.

@Hexalon
Created April 19, 2016 20:12
Show Gist options
  • Save Hexalon/4a7573182007b3950fce381f9936c634 to your computer and use it in GitHub Desktop.
Save Hexalon/4a7573182007b3950fce381f9936c634 to your computer and use it in GitHub Desktop.
Converts input string to a hex value
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.117
Created on: 3/22/2016 10:15
Created by: Colin Squier <hexalon@gmail.com>
Filename: StringToHex.ps1
===========================================================================
.DESCRIPTION
Converts input string to a hex value.
#>
$StringToConvert = Read-Host -Prompt "Enter string to convert to hex"
$StringArray = $StringToConvert.ToCharArray()
Foreach ($Element in $StringArray)
{
$HexValue = $HexValue + [System.String]::Format("{0:X}", [System.Convert]::ToUInt32($Element))
$StringLength++
}
$StringLength = $StringLength * 2
Write-Output "Input string: $StringToConvert, Hex value: $HexValue, String length: $StringLength"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment