Shop OBEX P1 Docs P2 Docs Learn Events
using "&" with bits - a little confused — Parallax Forums

using "&" with bits - a little confused

tuffstufftuffstuff Posts: 24
edited 2013-08-04 17:17 in Propeller 1
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:
...
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

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-04 15:06
    The "WakeUp" example does not look correct. Where in the Propeller Manual did you find it?

    The final example is correct.

    I think the forum software is killing the percent signs in some of your post.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-08-04 15:09
    tuffstuff,

    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:
    $f0 == %1111_0000
    $90 == %1001_0000

    Does this address your concenrs, or was there something else that needs sorting out?

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-04 15:16
    tuffstuff,

    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.
  • tuffstufftuffstuff Posts: 24
    edited 2013-08-04 15:20
    Yes, I have been trying to edit it correctly. I will switch editors and try again. Thanks for your help everyone.
  • tuffstufftuffstuff Posts: 24
    edited 2013-08-04 15:30
    Ahhh, much better...

    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!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-04 15:45
    tuffstuff wrote: »
    Ahhh, much better...

    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. :smile:
  • tuffstufftuffstuff Posts: 24
    edited 2013-08-04 17:06
    Do you see something different on pg 148? Which download source are you using for the manual? Mine definitely uses an "&". I should probably use the source you got yours at. I will look into "Or" and "|", thanks for the tip!

    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...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-04 17:14
    tuffstuff wrote: »
    Do you see something different on pg 148? Which download source are you using for the manual? Mine definitely uses an "&". I should probably use the source you got yours at. I will look into "Or" and "|", thanks for the tip!

    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.
  • tuffstufftuffstuff Posts: 24
    edited 2013-08-04 17:17
    Cool! I'm going to grab new manual and prop tool. Have a great evening!
Sign In or Register to comment.