Path: chuka.playstation.co.uk!news From: Toby Hutton Newsgroups: scee.yaroze.beginners Subject: Re: Clever bit manipulation routines? Date: 27 Jul 1998 13:14:14 +1000 Organization: PlayStation Net Yaroze (SCEE) Lines: 22 Sender: thutton@TECH10 Message-ID: References: <35B79502.BC7489D6@nospam.easynet.co.uk> <35B7BB71.D869219@compuserve.com> NNTP-Posting-Host: 203.103.154.235 X-Newsreader: Gnus v5.3/Emacs 19.34 tjs@cs.monash.edu.au (Toby Sargeant) writes: > > 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