12

I have a hex file that I am attempting to convert to binary. I have performed this on Linux before using the command:

xxd -r -p mykey.hex > mykey.bin

But I cannot figure out how to do this same command on Windows. I have downloaded a few hex editor tools but not really sure how to use them to convert hex into a binary representation.

Is there a way to do this in Windows, or are there any similar tools out there that would allow me to do this?

bertieb
  • 7,543
Kevin
  • 321

9 Answers9

20

VIM 7.x contains xxd for Windows

https://ftp.nluug.nl/pub/vim/pc/gvim73_46_s.zip

C:\Program Files (x86)\Vim\vim74>.\xxd -v
xxd V1.10 27oct98 by Juergen Weigert (Win32)

C:\Program Files (x86)\Vim\vim74>dir xxd.exe 10/08/2013 12:33 PM 70,144 xxd.exe

C:\Program Files (x86)\Vim\vim74>file xxd.exe xxd.exe; PE32 executable for MS Windows (console) Intel 80386 32-bit

Cygwin has one also

C:\cygwin\bin>.\xxd.exe -v
xxd V1.10 27oct98 by Juergen Weigert

C:\cygwin\bin>dir xxd.exe 18/09/2015 05:44 AM 18,963 xxd.exe

C:\cygwin\bin>file xxd.exe xxd.exe: PE32+ executable (console) x86-64, for MS Windows

added

xxd is available https://sourceforge.net/projects/xxd-for-windows/

xxd v1.11, 8 jun 2013 by Juergen Weigert et al. (Win32)

C:\Users\User>C:\xxd1p11\xxd-1.11_win32\xxd.exe -v
xxd v1.11, 8 jun 2013 by Juergen Weigert et al. (Win32)

C:\Users\User>

barlop
  • 25,198
4

To convert a hex string into a binary file, this works in PowerShell Core 7.2.1:

$hex_string = '48656C6C6F2C20576F726C6421'
$hex_string_spaced = $hex_string -replace '..', '0x$& '
$byte_array = [byte[]] -split $hex_string_spaced
Set-Content -Path 'out.bin' -Value $byte_array -AsByteStream

That last line won't work in PowerShell 5.1, but you can do this instead:

Set-Content -Path 'out.bin' -Value $byte_array -Encoding Byte

PowerShell comes pre-installed with Windows.

durette
  • 394
2

use powershell format-hex command:

PS C:\path\path\Documents\blah> format-hex Util3.class


           Path: C:\blah\blah\Documents\blah\Util3.class

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   CA FE BA BE 00 00 00 34 00 1F 0A 00 07 00 10 09  Êþº¾...4........
etc...
mcgyver5
  • 1,121
1

WinHex is the best for you to kick off stupid DOS command.

  1. Open Hex file
  2. Edit>>Converter File
  3. In the dialog box, Select Intel Hex to Binary
  4. Hit OK button.
  5. Round up file Size? Click No.
  6. SAVE File as Bin.
0

I wrote this in C and tested it in Cygwin.

Usage:

gcc stdin_hex_to_stdout_bin.c -o stdin_hex_to_stdout_bin
echo '48656C6C6F2C20576F726C6421' | ./stdin_hex_to_stdout_bin
cat some_hex_text_file.txt | ./stdin_hex_to_stdout_bin

stdin_hex_to_stdout_bin.c

#include <stdio.h>
#include <stdbool.h>

int input_char_to_mask(int input_char);

int main() { int inputc; int outputc; int outputmask; int mask; bool high = false; do { inputc = getc(stdin); outputmask = input_char_to_mask(inputc); if (outputmask != 0xFF) { if (!high) { outputc = outputmask * 16; } else { outputc = outputc | outputmask; putc(outputc, stdout); } high = !high; } } while (inputc != EOF); return 0; }

int input_char_to_mask(int input_char) { switch (input_char) { case '0': return 0x00; case '1': return 0x01; case '2': return 0x02; case '3': return 0x03; case '4': return 0x04; case '5': return 0x05; case '6': return 0x06; case '7': return 0x07; case '8': return 0x08; case '9': return 0x09; case 'A': return 0x0A; case 'B': return 0x0B; case 'C': return 0x0C; case 'D': return 0x0D; case 'E': return 0x0E; case 'F': return 0x0F; case 'a': return 0x0A; case 'b': return 0x0B; case 'c': return 0x0C; case 'd': return 0x0D; case 'e': return 0x0E; case 'f': return 0x0F; default : return 0xFF; } }

phuclv
  • 30,396
  • 15
  • 136
  • 260
durette
  • 394
0

There is a native port of xxd to Win32.

See unxutils here for downloads.

Another source of Win32 ports of common GNU and/or *nix utilities is GnuWin32.

Added By Barlop

This answer is incorrect, see comments, xxd is not in unxutils, and not in gnuwin32 either.

barlop
  • 25,198
Greg Jandl
  • 142
  • 3
0

If you are nuts, you could try processing the characters via input and then outputting the values 8 bits at a time using a programming language

0

Use this hex to bin converted: (works in browser, no software install necessary)

http://matrixstorm.com/avr/hextobin/ihexconverter.html

gronostaj
  • 58,482
-1

You can use the free Mcumall GQ4X programmer software without the programmer. Select the device and load the hex file. Save as a bin file and that is it.

Paul
  • 4,854