Contents
How to send a hex string with netcat?
I have a binary file that I can send with netcat: What I really want to do is send the hex string directly. I’ve tried this: However, the above command just sends the ascii string directly to nc. I used the -r and -p switches for xxd: Thanks to inspiration from @Gilles’ answer, here’s a Perl version: Here a solution without xxd or perl:
What’s the best tool to convert binary to ASCII?
You can use xxd to convert from ASCII and binary. If you’re looking to do just base conversions between Hex, Octal, & Dec I usually use the basic calculator command line tool ( bc) to do such things.
How to convert a hex string to binary in Perl?
It can be done fairly easy in Perl. The following script converts hexadecimal to binary, ignoring any input character that isn’t a hexadecimal digit. It complains if an input line contains an odd number of hexadecimal digits. If you really need to stick to POSIX (e.g. on an embedded device), I recommend using Base64 instead of hexadecimal.
How to convert a hex string to binary using SED?
With sed you can generate a escaped pattern: If you have xxd, that’s easy: it can convert to and from hexadecimal. I don’t think there’s a reasonable (and reasonably fast) way to convert hexadecimal to binary using only POSIX tools.
How to send a hex string to a remote device?
I’ve got some binary commands (which I’m representing as hex) that I need to send to a remote device (it’s an embedded data collection device) and observe the reply. and it sits there happy as a clam. The hex string I need to type in terminal and then send is something like: Where 02 is STX, 03 is ETX and so on.
Is there a way to convert a hex string to binary?
If you have xxd, that’s easy: it can convert to and from hexadecimal. I don’t think there’s a reasonable (and reasonably fast) way to convert hexadecimal to binary using only POSIX tools. It can be done fairly easy in Perl. The following script converts hexadecimal to binary, ignoring any input character that isn’t a hexadecimal digit.
What’s the best way to decode a hex string?
If you really need to stick to POSIX (e.g. on an embedded device), I recommend using Base64 instead of hexadecimal. You can use uudecode to decode Base64.