Skip to main content
fix to handle "0" in input
Source Link
Tim
  • 9.3k
  • 37
  • 54

If you really want a binary representation of the data, you could do it like this:

perl -ne 'printf "0x%04x %s\n", $o++, unpack("B*", $c) while $c = substr($_, 0, 1, "");') while length;' datafile 

The output will look a little like this:

0x0000 00000001 0x0001 00000010 0x0002 00110011 0x0003 00110100 0x0004 00001010 

If that's not what you want, please be a little more specific about what you're expecting.

If you really want a binary representation of the data, you could do it like this:

perl -ne 'printf "0x%04x %s\n", $o++, unpack("B*", $c) while $c = substr($_, 0, 1, "");' datafile 

The output will look a little like this:

0x0000 00000001 0x0001 00000010 0x0002 00110011 0x0003 00110100 0x0004 00001010 

If that's not what you want, please be a little more specific about what you're expecting.

If you really want a binary representation of the data, you could do it like this:

perl -ne 'printf "0x%04x %s\n", $o++, unpack("B*", substr($_, 0, 1, "")) while length;' datafile 

The output will look a little like this:

0x0000 00000001 0x0001 00000010 0x0002 00110011 0x0003 00110100 0x0004 00001010 

If that's not what you want, please be a little more specific about what you're expecting.

Source Link
Tim
  • 9.3k
  • 37
  • 54

If you really want a binary representation of the data, you could do it like this:

perl -ne 'printf "0x%04x %s\n", $o++, unpack("B*", $c) while $c = substr($_, 0, 1, "");' datafile 

The output will look a little like this:

0x0000 00000001 0x0001 00000010 0x0002 00110011 0x0003 00110100 0x0004 00001010 

If that's not what you want, please be a little more specific about what you're expecting.