Path: chuka.playstation.co.uk!tjs From: tjs@cs.monash.edu.au (Toby Sargeant) Newsgroups: scee.yaroze.beginners Subject: Re: Clever bit manipulation routines? Date: 24 Jul 1998 03:53:11 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 16 Message-ID: References: <35B79502.BC7489D6@nospam.easynet.co.uk> <35B7BB71.D869219@compuserve.com> NNTP-Posting-Host: indy19.cs.monash.edu.au X-Newsreader: slrn (0.9.5.1 UNIX) 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