Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a hex escaped char in Powershell

Is there any way to write something like this in Powershell? (Linux would be with Perl)

char foo = '\x41';

I need to input some non-printable characters to one of my programs

like image 823
Bur0k Avatar asked Jul 08 '14 07:07

Bur0k


People also ask

What is format Hex?

Description. The Format-Hex cmdlet displays a file or other input as hexadecimal values. To determine the offset of a character from the output, add the number at the leftmost of the row to the number at the top of the column for that character.

How convert decimal to Hex in PowerShell?

To convert decimal to Hex in PowerShell app, use '{0:x}' -f to format strings by using the format method of string objects and decimal number. It will convert decimal to hex string in PowerShell.

What does Char mean in PowerShell?

The [char[]] is simply an explicit declaration of a character array to over ride any odd default PowerShell behavior.


1 Answers

You can do it by casting an int to char.

With a decimal number :

 $foo = (65 -as [char])

And from hexa :

 $foo = (0x41 -as [char])

Both will set $foo to A

like image 173
Perfect28 Avatar answered Oct 05 '22 02:10

Perfect28