X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f X-Recipient: geda-user AT delorie DOT com X-Envelope-From: paubert AT iram DOT es Date: Fri, 31 Jan 2014 23:08:45 +0100 From: Gabriel Paubert To: geda-user AT delorie DOT com Subject: Re: [geda-user] Re: refdes renumber Message-ID: <20140131220845.GA29613@visitor2.iram.es> References: <1391182300 DOT 2023 DOT 11 DOT camel AT AMD64X2 DOT fritz DOT box> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Spamina-Bogosity: Ham Note-from-DJ: This may be spam Reply-To: geda-user AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: geda-user AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Fri, Jan 31, 2014 at 08:07:09PM +0000, Rupert Swarbrick wrote: > Алексей Харьковский > writes: > > This is simple: > > In [20]: ~0 > > Out[20]: -1 > > For other readers who (like me) are being slow today, the ~ operator > performs unary bitwise NOT. Apparently, integers in Python are > explicitly two's complement. I don't even know if there are still non two's complement machines being manufactured. And if these exotic beasts do exist, Python has probably not been ported to them. Basically today, all machines you can afford to buy use 2's complement integer, have word sizes which are a power of 2, and use IEEE-754 floating point. Well, IBM mainframes (not that an individual can afford one) still allow to use the original S/360 hexadecimal FP format, but they also support IEEE FP (plus decimal floating point for comercial workloads). This said, there is another important point: for an array of n elements, valid indices in Python are in the range from -n to n-1. The range 0 to n-1 is the familiar zero-based indexing used in C and other languages, negative indices run backwards from the end of the array so a[-n] is the first element and a[-1] the last. [Note that I don't think that this definition is a good idea: it may hide bugs when you have a complex indexing expression which is off by one and the Python interpreter will happily access the last element of an array instead of throwing an exception for out of bounds access. There are cases where it is handy but I am of the strong opinion that it is more dangerous than useful.] Gabriel