---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id A1DAE4201AC; Wed, 28 Jan 2004 17:28:58 -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 <16.00CC1CBA@cherry.ease.lsoft.com>; Wed, 28 Jan 2004 20:28:50 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 2029 for PICLIST@MITVMA.MIT.EDU; Wed, 28 Jan 2004 20:28:42 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 1835; Wed, 28 Jan 2004 20:28:26 -0500 Received: from mta02-srv.alltel.net [166.102.165.144] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with SMTP ; Wed, 28 Jan 2004 20:28:25 EST X-Comment: mitvma.mit.edu: Mail was sent by mta02-srv.alltel.net Received: from alltel.net ([216.170.9.73]) by mta02-srv.alltel.net with ESMTP id <20040129012827.TLJL319.mta02-srv.alltel.net@alltel.net> for ; Wed, 28 Jan 2004 19:28:27 -0600 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1 X-Accept-Language: en-us MIME-Version: 1.0 References: <23075D38FE1C8144847DFAECA3565F270173E37E@pai-smx-01.europe.bkhm.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <40186186.2030109@alltel.net> Date: Wed, 28 Jan 2004 19:27:34 -0600 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: Jim Korman Subject: Re: [PIC:] divide by 10 question To: PICLIST@MITVMA.MIT.EDU Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856182 Michael Rigby-Jones wrote: >>-----Original Message----- >>From: Andrew Kieran [mailto:akieran@UREACH.COM] >>Sent: 28 January 2004 15:00 >>To: PICLIST@MITVMA.MIT.EDU >>Subject: Re: [PIC:] divide by 10 question >> >> >>There are many solutions, but two in particular that I would >>consider: >> >>1) >>o starting with number to be divided in 'value1' >>o Shift right, store result in 'value1' and 'value2' >>o shift right, 'value1' two more times, storing result in >>'value1' o subtract 'value2' from 'value1' o The result is the >>original 'value1' divided by 10 >> >>This works likes this: >>rrf - divides by two, store in 'value2' >>rrf - now divided by four >>rrf - now divided by eight >>subtract 'value2' - now divided by ten >> >>Note also that the state of the carry flag after the last >>shift can be used to determne whether to round-up the result >> > > Have you actually tried this? It seems to be a fairly common assumption > that division can be performed like this by reversing the method you would > use for multiplication. It simply does not work, never has and never will. > > The only way to use shifts, additions and subtractions to perform division > is to break the divisor down into it's binary powers, as per my previous > post. > > Regards > > Mike > Try this instead x <- x div 2 x <- x - 10; x <- x div 2 x <- x div 2 will give you x div 10 Jim -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics .