Tags: binary, coded, dataset, dec2bin, decode, efficient, function, hex2bin, hex2dec, hexadecimal, huge, matlab, programming, translate

efficient hex2bin function

On Programmer » Matlab

2,090 words with 4 Comments; publish: Wed, 30 Apr 2008 19:13:00 GMT; (20093.75, « »)

I have a huge dataset that is coded in hexadecimal. I need to translate it i

nto binary to decode it. I have been using dec2bin(hex2dec(dataset)) which t

akes a long time for my data (~15 minutes). An example dataset is:

a=[3377

C8CA

8C4

2276

3376];

So my question is: does anyone have an efficient way to do the conversion? A

direct hex2bin function would be nice, I just haven't been able to figure o

ut how to vectorize the character substitutions (i.e. a 3 in hex becomes a 0

011 in binary).

Thanks for any ideas.

Andy

All Comments

Leave a comment...

  • 4 Comments
    • Hi,

      here is a reply by <us> in a previous thread :

      Jeff Tackett, "hex2bin function" #, 5 Oct 2004 6:03 pm </WebX?50.matlab.questionfor.info..matlab.questionfor.info..eeec1f6>

      Jrpme

      #1; Wed, 30 Apr 2008 19:15:00 GMT
    • I think my post made it clear that I was trying to go beyond the solutions p

      resented in the previous thread. If after re-reading my post you have any id

      eas, I'd be grateful. Thanks.

      Andy

      #2; Wed, 30 Apr 2008 19:16:00 GMT
    • Andy wrote:

      >

      > I think my post made it clear that I was trying to go beyond the

      > solutions presented in the previous thread. If after re-reading my

      > post you have any ideas, I'd be grateful. Thanks.

      You could always turn your entire HEX stream into a binary stream

      using lookup tables. And then reshape to whatever word length you

      need:

      bits=dec2bin(0:15)';

      idx('0123456789ABCDEF')=1:16;

      a=['3377C8CA08C422763376'];

      reshape(bits(:,idx(a)),length(a)/4,[])

      ans =

      0011111011100011

      0111000110001110

      1101000000011101

      1010010000010011

      0110100000110010

      #3; Wed, 30 Apr 2008 19:17:00 GMT
    • Steve Amphlett wrote:

      >

      <snip, posted with errors before checking...

      I meant to post this:

      bits=dec2bin(0:15)';

      idx('0123456789ABCDEF')=1:16;

      wordlength=4;

      a=['3377C8CA08C422763376'];

      reshape(bits(:,idx(a)),[],length(a)/wordlength)'

      ans =

      0011001101110111

      1100100011001010

      0000100011000100

      0010001001110110

      0011001101110110

      #4; Wed, 30 Apr 2008 19:18:00 GMT