flipping MSB

Home Forums General Programming flipping MSB

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #724
    msepsis
    Participant
      • Topics: 219
      • Replies: 732
      • Total: 951
      • ★★★

      the basic formula of what I want to do here is:
      wave[n]^0x80;

      I need to flip the Most significant "nibble".

      I thought I wanted to use CtrlrLuaBigInteger::shiftBits for this, I’m pretty sure that’s what I need but I’m probably just not using it right.

      Here’s what I’ve got. I’m all good up until the first "–" commented part about flipping.

      [code:ljkm80fh]sample1MSB = CtrlrLuaBigInteger(wb7)
      sample1MSBbin = sample1MSB:toString(2,8)
      console ("Our unsigned 14 bits are: "..sample1MSB:toString(2,8))
      console (string.format ("sample1msb binary=(%d)", sample1MSBbin))

      sample1bitRange = sample1MSB:getBitRangeAsInt (0,7)
      console (string.format ("sample1 bit range=%.2x", sample1bitRange, sample1bitRange))

      –flip the bit for s1SMSB (sample 1’s signed MSB)

      — s1SMSB = sample1MSB:shiftBits (8,4)
      — console (string.format (s1SMSB))

      — s1SMSB = sample1MSB:shiftBits(0,0)
      — console (string.format (s1SMSB))

      s1SMSB = sample1MSBbin:shiftBits(4,0)
      console (string.format (s1SMSB))

      [/code:ljkm80fh]

      This is giving me a lua runtime error: [i:ljkm80fh]attempt to call method ‘?’ (a nil value)[/i:ljkm80fh]

      What am I doing wrong here?

      Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

      #4810
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        First of all you are converting types from BigInteger to string and trying to call BigInteger method on a string object, watch your object naming. The shiftBits method does not return anything, so you can’t type:
        [code:1k8ag3ky]
        s1SMSB = sample1MSBbin:shiftBits(4,0)
        [/code:1k8ag3ky]
        the shift bits operation happens on the object itself

        For example assuming that what you wanted to do is shiftBits on an object this is how you can do it
        [code:1k8ag3ky]
        sample1MSB = CtrlrLuaBigInteger(1249)
        sample1MSBbin = sample1MSB:toString(2,8)
        console ("Our unsigned 14 bits are: "..sample1MSB:toString(2,8))
        console (string.format ("sample1msb binary=(%d)", sample1MSBbin))

        sample1bitRange = sample1MSB:getBitRangeAsInt (0,7)
        console (string.format ("sample1 bit range=%.2x", sample1bitRange))

        sample1MSB:shiftBits(4,0)
        console (sample1MSB:toString(2,2))
        [/code:1k8ag3ky]

        #4811
        msepsis
        Participant
          • Topics: 219
          • Replies: 732
          • Total: 951
          • ★★★

          Ok that helps my understanding, but I realize I was going about what I’m trying to do (get a signed value by flipping the MSB) the wrong way. shiftBits moves the bits left.

          So how would I go about using bigInteger to flip, say 1010 to 0101? I believe that is in essence what I need to do.

          I suppose I could set up a cascade of if/then statements using getBit and setBit, if value is 0, set to 1, vice versa but was wondering if there’s some bitwise/complement operation that can just flip the bits?
          Thanks again for your help

          Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

          #4812
          atom
          Keymaster
            • Topics: 159
            • Replies: 2945
            • Total: 3104
            • ★★★★★

            I’d need to know what do you mean by flip, do you want a mirror image ?
            [code:2wysyh8k]
            0011010 <flip> 0101100
            [/code:2wysyh8k]

            If you want to shift right then the manual says how to do that:
            http://www.rawmaterialsoftware.com/juce … 01c0a68f48
            [code:2wysyh8k]
            Shifts a section of bits left or right.

            Parameters:
            howManyBitsLeft how far to move the bits (+ve numbers shift it left, -ve numbers shift it right).
            startBit the first bit to affect – if this is > 0, only bits above that index will be affected.
            [/code:2wysyh8k]

            #4813
            msepsis
            Participant
              • Topics: 219
              • Replies: 732
              • Total: 951
              • ★★★

              No, flip as in if the bit is 0, set it to 1

              http://en.wikipedia.org/wiki/Bitwise_operation#NOT

              Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

              #4815
              atom
              Keymaster
                • Topics: 159
                • Replies: 2945
                • Total: 3104
                • ★★★★★

                That might not be possible cause i didn’t implement the operators for the BigInteger, i thing this can be done mathematicly using simple math operations but i can’t tell you exactly how. I’ll implement the rest of the BigInteger class and then i think it might be done.

                #4814
                msepsis
                Participant
                  • Topics: 219
                  • Replies: 732
                  • Total: 951
                  • ★★★
                  "atom":2kbh8qte wrote:
                  That might not be possible cause i didn’t implement the operators for the BigInteger, i thing this can be done mathematicly using simple math operations but i can’t tell you exactly how. I’ll implement the rest of the BigInteger class and then i think it might be done.[/quote:2kbh8qte]

                  Ok. And the math operations available are those you mentioned in the thread from a few weeks back on two’s compliment format?

                  [i:2kbh8qte]First of all the expression can be any mathematical expression details: http://www.rawmaterialsoftware.com/juce … ml#details

                  Second of all some additional functions are implemented to help with some maths: api/class_ctrlr_modulator_processor.html#afed723cfa2eb7c5db71c1e30e919302b[/i:2kbh8qte]

                  Thanks as always for your patient and honest help! always nice to know the constrictions as well as the possibilities!

                  Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

                Viewing 7 posts - 1 through 7 (of 7 total)
                • The forum ‘Programming’ is closed to new topics and replies.
                There is currently 0 users and 93 guests online
                No users are currently active
                Forum Statistics
                Threads: 2,495, Posts: 17,374, Members: 77,605
                Most users ever online was 12 on January 22, 2019 3:47 pm
                Ctrlr