I would like to generate a raw binary packet from hex in the command line for the purpose of testing a protocol. I'm hoping its simpler to do it this way than writing an aplication.Here is what currently happens:echo '0A' | xxd  -b0000000: 00110000 01000001 00001010What i would like to have is:echo '0A' | xxd  -b0000000: 00001010    orecho '0A' | xxd  -b0000000: 01010000    Since I'm not jet sure about the required endianess. I would like to be able to change it when necessary.Is this achievable?
Can xxd be used to output the binary representation of hex number , not a string?
bash;conversion;binary
echo '0A' produces three characters: 0 A NL; xxd -b will then print those three characters in binary. If you wanted just the single byte whose value is 10 (i.e. hexadecimal A), you could write (in bash):echo -n $'\x0A'      ^ ^  ^      | |  |      | |  +-- `\x` indicates a hexadecimal escape      | +----- Inside a $' string, escapes are interpreted      +------- -n suppresses the trailing newlineA better alternative would be printf '\x0A'; printf interprets escape sequences in the format string, and does not output implicit newlines. (This is the Posix-compatible solution, which should work on any Posix-compatible shell.) Yet another bash possibility is echo -n -e '\x0A'; the (non-standard) -e flag asks echo to interpret escape sequences.I have no idea why you would expect echo '1' | xxd  -b to output the equivalent of hex 50. How are you expecting xxd to understand that 0A is a hex number and 1 isn't? Furthermore, why 50? (The ascii code for the character 1 is hex 31.)Endianness does not affect bytes. The order of bits inside a byte is entirely conceptual until the byte is transmitted over a serial line and even then it is only visible with an oscilloscope or something similar.