Home › Forums › General › Programming › flipping MSB
- This topic has 6 replies, 2 voices, and was last updated 11 years, 6 months ago by atom.
-
AuthorPosts
-
September 30, 2012 at 4:35 am #724
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,
console ("Our unsigned 14 bits are: "..sample1MSB:toString(2,)
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
September 30, 2012 at 1:38 pm #4810First 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 itselfFor 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,
console ("Our unsigned 14 bits are: "..sample1MSB:toString(2,)
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]September 30, 2012 at 7:12 pm #4811Ok 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 helpMonstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
September 30, 2012 at 7:23 pm #4812I’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]September 30, 2012 at 7:27 pm #4813No, 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
September 30, 2012 at 7:40 pm #4815That 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.
September 30, 2012 at 7:59 pm #4814"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
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.