using "&" with bits - a little confused
tuffstuff
Posts: 24
Hi, very new to Spin and working with data on this level ( I work with a lot of Python and SQL ). I was trying to understand using "&" as a bitwise operator and I came across what seems like conflicting info. I'm hoping you all can set me straight.
I was examining the code from the "sick day synthesizer" and I was confused by this part:
Despite this looking like boolean logic, I figured it must have been some form of addition. I started poking around in the propeller manual and found the following example
This is not the same thing. Any help sorting out the differences here would be appricated.
I was examining the code from the "sick day synthesizer" and I was confused by this part:
... if ( runningStatus & $f0 ) == $90 ...
Despite this looking like boolean logic, I figured it must have been some form of addition. I started poking around in the propeller manual and found the following example
... CON _xinfreq = 4096000 Reset = %00100000 Initialize = %00010000 WakeUp = Reset & Initialize Here, WakeUp is still set to %00110000 at compile time, but it is now more obvious to future readers that the WakeUp symbol contains the binary codes for a Reset and an Initialize sequence for that particular application. ...Cool, I was right, but then I came across the bitwise operator section and found this example...
... X := %00101100 & %00001111 The above example ANDs %00101100 with %00001111 and writes the result, %00001100, to X. ...
This is not the same thing. Any help sorting out the differences here would be appricated.
Comments
The final example is correct.
I think the forum software is killing the percent signs in some of your post.
Welcome to the Parallax forum!
Both examples you cite are Boolean bitwise ANDs (although the constants in the latter example should be prepended with "%" to indicate binary representation). In the first example, the constants are written in hexadecimal format, but they are still binary numbers internally, viz:
$90 == %1001_0000
Does this address your concenrs, or was there something else that needs sorting out?
-Phil
It looks like the percent sign problem is getting worse. It's a side effect of the WYSIWYG editor. You need to change your settings to "Basic Editor" in order to post percent signs correctly. This is a big pain IMO.
I found the faulty example on page 148 of the WebPM-v1.1 pdf.
I'm assuming that in the CON example the "&" should have been a "+", yes?
Thanks again for the help!
The example uses a bitwise "or" "|" (as it should).
You should probably lay off the laser projects for a while to let your eyes recover.
p.s. this is usually what I look like when I use laser products --> :cool: <-- but mostly for looks. My fiends tell me the flash its mostly harmless...
I just noticed. Mine is v1.2. I was part of the Prop Tool v1.3.
They must have fixed the typo between v1.1 and v1.2. So it looks like the shades have been working after all.