pl@kaarne.tut.fi (Pertti Lehtinen) (01/12/89)
From article <4061@hubcap.UUCP>, by mcvax!etive.ed.ac.uk!gvw@uunet.UU.NET (MOBY): > I'm looking for "clever" programming tricks. For example, > consider the following problem: > > Given a computer word W in which one or more bits are set, > change the lowest set bit from 1 to 0, and set the corresponding > bit in another word B to 1. Eg. if the input is W = 0x0860, > return W' = 0x0840 and B' = 0x0020. This can be also done by: B' = (~W+1)&W W' = W^B > I would like to hear about similar tricks that people have invented/ > discovered. In particular, I'm looking for fast ways to count the > number of 1 bits in a word (on machines that don't have this as a > machine instruction :-), and trying to find a description of a > mythical technique for creating doubly-linked lists using single > pointers and XOR operations. > About XOR-chaining there is article in Doctor Dobbs Journal, June, 87 and also September 87. Later article discusses about handling of binary trees without stacks (Using XOR-technicues). Yours Pertti Lehtinen pl@tut.fi pl@tut.fi ! All opinions expressed above Pertti Lehtinen ! are preliminary and Tampere University of Technology ! in subject to change Software Systems Laboratory ! without any further notice.