Path: chuka.playstation.co.uk!news From: Philip Gooch Newsgroups: scee.yaroze.beginners Subject: Re: Clever bit manipulation routines? Date: Fri, 24 Jul 1998 09:55:02 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 27 Message-ID: <35B84BE6.80FC4CA7@easynet.co.uk> References: <35B79502.BC7489D6@nospam.easynet.co.uk> <35B7BB71.D869219@compuserve.com> NNTP-Posting-Host: 193.131.140.246 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) Toby Sargeant wrote: > On 24 Jul 1998 12:05:57 +1000, Toby Hutton wrote: > [snip] > >The libraries often use 12 bit fixed point math. This means that 4096 > >is 1, 2048 is 1/2 and 512 will be an eighth. 512 in hex is 0x0200 and > >511 is 0x01ff. To limit a value between 0 and +511 you simply: > > > >val &= 0x1ff; > > sadly, that won't do what was wanted. That will wrap all values into a range, > whereas the intention was to compute f(x), where f(x)=-45 if x<-45, f(x)=x > if -45<=x<=45, f(x)=45 if 45 > while you could do that with bitops, it would be messier and slower than the > equivalent test/assigns. > > toby. But the point Toby S made about using 4096 as 1 etc is still valid, and useful. In fact I do normally do that - the example I gave using 45 degrees was just for illustration. Phil