-1

I am solving the challenge about splitting with simultaneous progress monitoring here. Assume the detectable field of the header is FA FA FA FA in Hex.

Steps in splitting by the field

  • binary to binary ascii of the data as described here
  • bin2hex
  • mark split points by gsed 's/FA FA FA FA/\0/100g'
  • split where marks \0 by pseudocode split -p'\0' input.txt which is discussed here

How can you do the conversion bin2hex?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

1

Couldn't access the link you shared...

But, you can use bc (bash calculator) utility for the conversions... Maybe there will be a better approach (which i am unaware of :-))

For hex to binary:

v=F; echo "ibase=16;obase=2;$(echo $v)" | bc

This will convert 0xF to 1111b.

ibase is the input base system (16 => hex). obase is the output base system (2 => binary).

For binary to hex:

v=1111; echo "ibase=2;obase=10000;$(echo $v)" | bc

This will convert 1111b to 0xF.

ibase is the input base system (2 => binary). obase is the output base system (10000 => hex (obase should be mentioned using ibase as the base system, our obase, 10000b = 16 decimal => hex)).

Arjun Mathew Dan
  • 5,240
  • 1
  • 16
  • 27
  • 1
    check the output of $(echo `sed '1q;d' /Users/masi/Dropbox/123/r3.raw`)... it should be a binary value... as u r trying to convert from binary to hex... – Arjun Mathew Dan Jun 24 '15 at 12:24
  • How efficient such conversion can be? You go from defining a variable, to echoing and to bc, which is calling the shell each time, taking probably much resources. I put a better focus in the following thread for a single tool in doing this task http://stackoverflow.com/q/31026541/54964 – Léo Léopold Hertz 준영 Jul 27 '15 at 11:08