Skip to content

Instantly share code, notes, and snippets.

@jqntn
Created May 5, 2025 22:10
Show Gist options
  • Select an option

  • Save jqntn/36680f4cb96592d8ef06f7bd703d3015 to your computer and use it in GitHub Desktop.

Select an option

Save jqntn/36680f4cb96592d8ef06f7bd703d3015 to your computer and use it in GitHub Desktop.
Fast xxd -i implementation in Windows PowerShell
$file_name = ($args[0] -replace '\W', '_').ToLower()
$file_bytes = [System.IO.File]::ReadAllBytes($args[0])
$hex_array = New-Object string[] $file_bytes.Length
for ($i = 0; $i -lt $file_bytes.Length; $i++) {
$hex_array[$i] = '0x{0:x2}' -f $file_bytes[$i]
}
$hex_string = [string]::Join(', ', $hex_array)
"unsigned char $file_name[] = { $hex_string };"
"unsigned int ${file_name}_len = $($file_bytes.Length);"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment