Processing Bit Strings

Discussion in 'Perl' started by Matt Taylor, Feb 16, 2004.

  1. Matt Taylor

    Matt Taylor Guest

    I have a script which runs postprocessing on some data and formats the
    results into a table. This is compiled into a C project. The perl script
    creates an 800x800 matrix of bits (~800 KB). After creating an enormously
    long string, it formats it for C source as follows:

    # Pad out the end of the bit string to a byte
    $bitstr .= '0' x ((8 - (length($bitstr) % 8)) % 8);

    # Create an array of bytes
    @bytes = ();
    while(length($bitstr) > 0)
    {
    push(@bytes, sprintf('0x%02X', ord(pack('b8', substr($bitstr, 0, 8)))));
    $bitstr = substr($bitstr, 8);
    }

    # Down here I have code to print the array

    This takes several minutes to run under perl 5.8 on my Pentium 4 2.53 GHz. I
    was wondering if there was a faster way to do this? Several minutes is
    usually acceptable, but in a debug cycle I run this script frequently, and
    it would make my life much easier if it were faster.

    -Matt
     
    Matt Taylor, Feb 16, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    540
    Michael Foord
    Sep 17, 2004
  2. Replies:
    3
    Views:
    1,855
    Timothy Bendfelt
    Jan 19, 2007
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    810
    Malcolm
    Jun 24, 2006
  4. Replies:
    9
    Views:
    1,049
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    204
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page