Path: chuka.playstation.co.uk!news From: Philip Gooch Newsgroups: scee.yaroze.beginners Subject: Clever bit manipulation routines? Date: Thu, 23 Jul 1998 20:54:45 +0100 Organization: philg@nospam.easynet.co.uk Lines: 27 Message-ID: <35B79502.BC7489D6@nospam.easynet.co.uk> Reply-To: philg@nospam.easynet.co.uk NNTP-Posting-Host: philg.easynet.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 (Macintosh; I; PPC) Hello folks I've got a few lines of code that look ugly and wondered if there's a clever bit manipulation routine using shifting, ANDing and complement or something to achieve the same thing. I'm sure there's a way, just can't figure it out. Basically: if (gPlayer.turningAngle > 45) gPlayer.turningAngle = 45; if (gPlayer.turningAngle < -45) gPlayer.turningAngle = -45; I'm convinced there's something out there that will handle both of these in one line, something like (~(gPlayer.turningAngle) & 0x2d) >> something. Though obviously not this! Do you see what I'm getting at? Something that will leave the variable unchanged unless it is greater or less than a certain value, in which case it becomes that value. Anyone have any ideas? Cheers Phil