DarwinBotsManual
Open the app EspañolES

&

Bitwise and of the top two numbers: keeps only the bits that are set in both. Good for checking and clearing flags.

Facts

Word
&
Family
Bitwise
Integer stack
pops 2, pushes 1
What it does
Pops two numbers and pushes one with only the bits that are set in both turned on. With an empty stack it gives 0.
Cost
Bitwise command
Runs
inside a gene: in the condition (cond) and in the body (start or else)

a b & pops two numbers and leaves a number with a bit set only where that bit is set in both a and b. 12 10 & gives 8: in binary, 1100 and 1010 share only the bit worth 8.

Stack beforeAfter &
12 108
7 44
5 20

It has two main uses:

A useful special case: x 1 & leaves 1 if x is odd and 0 if it is even. With .robage it makes a gene that runs every other cycle:

' moves forward only on cycles where its age is even
cond
  *.robage 1 & 0 =
start
  10 .up store
stop

With negatives it works on the two's complement: -1 has all its bits set, so x -1 & leaves x as is. With an empty stack it operates on zeros and gives

  1. Or and exclusive or are | and ^; to combine trues and

falses (not numbers) there is and.