in reply to Re^9: pack/unpack binary editing
in thread pack/unpack binary editing

Thanks for all your help. Regarding the code you posted. You'll have to fogive my ignorance. Could you break down your substitution line. I don't really understand what it's doing. I ran the code. Not sure how much faster it is 'cause I stopped it. My results were wrong. The substitution isn't quit right. I need to be able to look at every 2 bits and then determine if they are a 11 or a 00 then replace and move on to the next 2 bits.

Replies are listed 'Best First'.
Re^11: pack/unpack binary editing
by BrowserUk (Patriarch) on Feb 10, 2005 at 15:24 UTC

    Okay. Re-reading your code, I think that you only want to replace the paired bits on even bit boundaries?

    Substitute this for the other regex.

    $bits =~ s[(..)][ ## Look at every pair of bits $1 eq '00' ## If they are 00 ? '11' ## replace them 11 : $1 eq '11' ## If they are 11 ? '00' ## replace them with 00 : $1 ## else leave them alone ]ge;

    That will slow it down a bit, but it will still run quicker than splitting the string into and array etc.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      OK, that piece of code worked perfect. However, now when I look at the file the first frame is on synce but the rest are off by a few bits. I believe this to be because when we remove the bits prior to the sync and then pack it up the frame is no longer on a byte boundary. This is the problem I've been dealing with. If I remove a couple bits from the beginning then when I pack it up the files being padded to place it back on a byte boundary. I'm starting to think I'm going to have to just suck it up and either deal with the slowness or get a C programmer to do it. Any thoughts??
        ... the rest are off by a few bits.

        The only way that can be true, is if

      • the sync mark itself is not meant to be on a byte boundary.

        Ie. If it is meant be a few bits into each frame?

        This is possible and easily dealt with.

      • Or the frames are themselves are "a few bits" longer than 960 bytes, which doesn't makes much sense.

        Could you unpack the first 3 or 4 frames of the (raw) file to binascii and post them on your scratchpad?


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.