MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Working with binaries


On May 4, 2004, at 12:03 pm, Luca wrote:

> I was also trying to find the function NOT, i.e. that function which 
> gives:
>
> !1 = 0
> !0 = 1
>

The function Not is just defined for truth values. Not[True] yields 
False, and vice versa.

Why not just use something like:
	
	MyNot[n_] := If[n == 0, 1, 0]

Replace the "==" with "===" if you want to force everything except 0 to 
1.

If you want to extend the built-in Not function, you'll need to 
temporarily unprotect the symbol before defining the extension. In this 
case, use

ClearAttributes[Not,Protected];
Not[0]:=1;
Not[1]:=0;
SetAttributes[Not,Protected];

This will then give you the behaviour you want:

In[37]:=
Not[0]
Not[1]

Out[37]=
1

Out[38]=
0

In[42]:=
!0//Print
!1//Print

 From In[42]:=
1

 From In[42]:=
0
--
J. McKenzie Alexander
Department of Philosophy, Logic and Scientific Method
London School of Economics and Political Science
Houghton Street, London WC2A 2AE



  • Prev by Date: Re: Do Modules Produce Side Effects?
  • Next by Date: RE: Do Modules Produce Side Effects?
  • Previous by thread: Working with binaries
  • Next by thread: Re: Working with binaries