Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Last active November 2, 2024 20:11
Show Gist options
  • Select an option

  • Save ninmonkey/a1e5edd442abf3f2e24c4fdc44b56dd4 to your computer and use it in GitHub Desktop.

Select an option

Save ninmonkey/a1e5edd442abf3f2e24c4fdc44b56dd4 to your computer and use it in GitHub Desktop.
Nonsense example. Just showing a round trip.
$originalMessage = "hi πŸ’ world"
$enc = [Text.Encoding]::GetEncoding('utf-8')
$bytes = $enc.GetBytes( $originalMessage)
$hexStr = [Convert]::ToHexString( $bytes )
$asBytes = [Convert]::FromHexString( $hexStr )
$roundTrip = $enc.GetString( $AsBytes )
[pscustomobject]@{
Original = $originalMessage
Enc = $enc
Bytes = $bytes
HexStr = $hexStr
BytesAgain = $asBytes
RoundTrip = $roundTrip
IsValid = $roundTrip -eq $originalMessage
}
<#
output
Original : hi πŸ’ world
Enc : System.Text.UTF8Encoding+UTF8EncodingSealed
Bytes : {104, 105, 32, 240…}
HexStr : 686920F09F909220776F726C64
BytesAgain : {104, 105, 32, 240…}
RoundTrip : hi πŸ’ world
IsValid : True
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment