SynthMaker

'&' symbol in component. Bitwise And. Conditional

Archive · 2005 4 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

cbit ·

Jorge kindly just gave me a mini tutorial about creating conditional type statements in SMs code component, using the '&' character.

While the code in the simple example ive been fiddling with (a ramp generator) sort of makes sense to me.. im still not understanding how 'And'ing works really.

streamin in; streamout out; float f; f=f+in;//0.4 is attached to 'in', so f increases by .4 with each iteration.. f=(f<1.0)&f;// this is the part i don't completely get out=f;

f=(f<1.0)&f : this seems to be analogous to 'if f<1, set f to f, otherwise set f to zero', which resets the ramp waveform when it reaches 1.

I understand that a comparison will evaluate to 0 if false and 1 if true, and i think this is important in this context too somehow (?)..

I suppose i'm confused about exactly how '&' works here (i come from an actionscript and php coding background) .. any pointers or keywords to google for, or articles to read would be much appreciated. Thanks![/code]

stefan ·

it results in a "bitwise and"

That means that you'll get either: f = 0 & f or f = all_bits_set_to_one & f

if you google on bitwise and, you will get more information on how that works. But basicly

0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 = 1

beno ·

To elaborate a little further, your code has:

f=(f<1.0)&f

so let's say f = 0.101011 when converted to binary for example

so since this is less then 1, you will get

f = 1&f

This does a bitwise AND of 1 and every bit of f. According to stefan's desciptions above, 1 ANDed with any value just gives back that value, so this just gives back f again so f doesn't change.

Now if f = 1.101011 when convereted to binary, it is now greater than 1. So the first equation now becomes

f = 0&f

Again following the descriptions above, we see that 0 ANDed with anything is zero. So going bit by bit we are simply left with f = 0.

Hope that helps.

Ben

cbit ·

thanks for your replies,

ben: yours in particular was very helpful.. combined with the super simple binary primer i found here: http://www.litfuel.net/tutorials/bitwise.htm, (by googling 'bitwise and php', thanks stefan 🙂 )it now makes sense to me.

thanks a lot!

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.