[UPD] bitwiseShiftLeft

Sean Shao shaosean at hotmail.com
Fri Nov 25 04:16:35 EST 2005


After checking the code from yesterday's posting, I noticed that I was still 
using some plain simple RunRev handlers for the "shiftLeft" bitwise 
operator, this would cause it to fail on many occasions.. I've spent the 
last 6 hours straight (less a few chatRev breaks) to get code that won't 
fail (hopefully ;-) and can handle 32-bit signed integers..

So here is the fix for shiftLeft (I'm working on a shiftRight fix):

function bitwiseShiftLeft p1, p2
  if (p2 >= 32) then return p1 * (2 ^ (p2 MOD 32))
  if (p2 = 0) then return p1
  if (p2 < 32) then
    put baseConvert(p1, 10, 2) into p1
    repeat p2
      put 0 after p1
    end repeat
    return baseConvert(char -32 to -1 of p1, 2, 10)
  end if
end bitwiseShiftLeft

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




More information about the use-livecode mailing list