Path: chuka.playstation.co.uk!news From: James Shaughnessy Newsgroups: scee.yaroze.beginners Subject: Re: Clever bit manipulation routines? Date: Mon, 27 Jul 1998 22:02:02 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 25 Message-ID: <35BCEACA.299@manc.u-net.com> References: <35B79502.BC7489D6@nospam.easynet.co.uk> <35B7BB71.D869219@compuserve.com> NNTP-Posting-Host: manc.u-net.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0 (Win95; I) Toby Hutton wrote: > If you used +/-31 instead of +/-45, why wouldn't > f(x) = ((x + 0x20) & 0x3f) - 0x20; work? It strips bits higher than 0x3f (=63 so bit-6 upwards) which is a problem because x needs to be signed. In this case f(-35) = 29 (when it should be -31) : if x is -35 then it is required that it gets limited to -31, but the f(x) above would give the wrong number because (x + 0x20) would equal 0xFFFD (-3 decimal) (assuming 16bit signed int) and when &'d with 0x3f it would then be 0x3d (61 decimal). Then the - 0x20 would make it 29. Just use this: limitRange(x, -45, 45); Later, Jim -- ----------------------------------------- James Shaughnessy james@manc.u-net.com http://www.netyaroze-europe.com/~shaughnj -----------------------------------------