---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id A2542690238; Sun, 01 Feb 2004 10:15:48 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <12.00CC7DCA@cherry.ease.lsoft.com>; 1 Feb 2004 13:15:12 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 1034 for PICLIST@MITVMA.MIT.EDU; Sun, 1 Feb 2004 13:15:06 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 1086; Sun, 1 Feb 2004 13:14:05 -0500 Received: from sprucegrove.com [12.151.22.244] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with ESMTP ; Sun, 01 Feb 2004 13:14:04 EST X-Comment: mitvma.mit.edu: Mail was sent by sprucegrove.com Received: (from jay@localhost) by sprucegrove.com (8.11.0/8.11.0) id i11IAQh28690 for PICLIST@MITVMA.MIT.EDU; Sun, 1 Feb 2004 13:10:26 -0500 X-Mailer: ELM [version 2.5 PL3] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <200402011810.i11IAQh28690@sprucegrove.com> Date: Sun, 1 Feb 2004 13:10:26 -0500 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: "D. Jay Newman" Subject: Re: [PIC:] AND, and OR To: PICLIST@MITVMA.MIT.EDU In-Reply-To: from "Ruben Undheim" at Feb 01, 2004 06:49:17 PM Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856757 > I have just subscribed to the mailing list, and want to try it out. > > Since I am relatively new to PIC-programming, and since I am not an expert in mathematics (I'm still quite young!), > I wondered what really happens when you AND's to numbers. > Why is for example "50 AND 100 = 32" (decimal numbers) or > "0xAF AND 0xCC = 0x8C" ???? > - and what happens when you OR's to numbers? This is basic boolean logic (google for boolean logic) and you will find better explanations. For my explanation I am using 1 and 0 instead of true and false, but microcontollers use 0 and 1. OK: Think of this as starting with single binary digits, x and y. AND The result is 1 if both x and y are both 1; the result is 0 otherwise x y result --- --- ------- 0 0 0 0 1 0 1 0 0 1 1 1 OR The result is 0 if both x and y are 0; the result is 1 otherwise (in other words, the result is 1 if x is 1 OR y is 1) x y result --- --- ------- 0 0 0 0 1 1 1 0 1 1 1 1 Exclusive OR (XOR) The result is 1 if either x or y (but not both) are 1; the result is 0 otherwise. x y result --- --- ------- 0 0 0 0 1 1 1 0 1 1 1 0 Now, when you are programming a PIC, you are doing entire bytes at a time. Therefore you are doing 8 bits compared to another 8 bits in parallel. So if X = 00001111 and y = 010101010, then x OR Y = 01011111 X AND Y = 00001010 X XOR Y = 01011010 I hope this helps. -- D. Jay Newman ! jay@sprucegrove.com ! Xander: Giles, don't make cave-slayer unhappy. http://enerd.ws/robots/ ! -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads .