Re: Working with binaries
- To: mathgroup at smc.vnet.net
- Subject: [mg47991] Re: [mg47990] Working with binaries
- From: "J. McKenzie Alexander" <jalex at lse.ac.uk>
- Date: Wed, 5 May 2004 08:10:58 -0400 (EDT)
- References: <200405041103.HAA02791@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
- References:
- Working with binaries
- From: Luca <luca@nospam.it>
- Working with binaries