Processing Bit Strings

From: Matt Taylor (para_at_tampabay.rr.com)
Date: 02/16/04

  • Next message: pawo: "perl 5.8.2/3 - thread started by a thread"
    Date: Mon, 16 Feb 2004 09:15:12 GMT
    
    

    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


  • Next message: pawo: "perl 5.8.2/3 - thread started by a thread"

    Relevant Pages

    • Re: Need to be able to add print option or save as option to the outpout of this script....
      ... First get all the names and shove them in an array. ... building script, then, start building the page, when you get to the section ... Then write the end bit of code into a string. ... If I'm right then this will display the html in a browser. ...
      (microsoft.public.scripting.vbscript)
    • Re: REQ - Help in editing a file - Script or Utility
      ... deal with it as an array. ... As the string gets bigger you're dealing with the need to ... going through the string 1 character at a time. ... I tested the script below on a 1.6 MB ...
      (microsoft.public.scripting.vbscript)
    • Re: Array Marshalling different between VB6 & Script to an interop C#
      ... as opposed to an array of strings. ... public void TestString ... ref string[] values ... Once we introduce the script ...
      (microsoft.public.dotnet.framework.interop)
    • Re: Splitting a string into separate characters
      ... Then separate the string so each letter is then stored ... > array items) so then I can do things with each letter on its own. ... Midreturns the Nth character in a string... ... Download details: Windows Script Documentation ...
      (microsoft.public.scripting.vbscript)
    • Re: Tcl C pass by reference
      ... >> At the moment I under stand how to pas usefull information back up to ... >> the script as a string but there are some C functions that pass up ... > string which can be evalto set an array ... ...
      (comp.lang.tcl)