32-bit operations
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 27, 2004
- 417 views
Hi all, it turns out that I can't use Juergen's routines after all. I need to do arithetic that can have temporary values that extend beyond Euphoria's 30-bit integer limit. Thanks to being reminded about the bits_to_int() and int_to_bits() routines, I've come up with this little function that gives me the correct values now. It seems to run fast enough for my uses too! global function ClipBits(atom pValue) if pValue > #FFFFFFFF or pValue < 0 then pValue = bits_to_int(int_to_bits(pValue,32)) end if return pValue end function I use it in this context ... global function TEA_encypher(atom y, atom z, atom k1, atom k2, atom sum) -- The input parameters are all 32-bit unsigned integers. -- I return a 32-bit unsigned integer -- The seperate assignments are there to ensure that I -- don't lose any precision by simulating 32-bit UINTs -- with atoms. y = ClipBits(y + ClipBits(z * 16)) -- z<<4 y = ClipBits(y + xor_bits(k1, z)) y = ClipBits(y + xor_bits(sum, (z / 32))) -- z>>5 y = ClipBits(y + k2) return y end function -- Derek