I have read in many places that if we want to retrieve the encoded byte value from a Unicode character that you should do the following. I'm doing everything in Powershell ISE as it has better character support. Same problems exist in a powershell
console.
[byte][char]'a'
Which outputs "97" which is 0x61 in Hex, which is the correct value. That's great.
Now if I do the following for a different character, in this case "€"
[byte][char]'€'
Cannot convert value "€" to type "System.Byte". Error: "Value was either too large or too small for an unsigned byte."At line:4 char:1+ [byte][char]'€'+ ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidCastIConvertible
So now let's try using [int16], which is bigger
[Int16][char]'€'
It returns "8364", which is not correct. It should return "128" as the hex code for "€" is "0x80".
How can I get my powershell to retrieve the correct character codes for some characters?