lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

   I'm still confused.  Ignoring rotates (which rotate the bits) CPUs tend to
support two forms of shifting, an unsigned variant (where 0 is copied in for
right shifts) and a signed variant (where the sign bit is copied for right
shifts) and are (nominally) used for multiplication/division by 2, which
makes it an arithmetic operation, and which I use to replace certain
exponential operations I used from Lua 5.1/5.2:

	x = 2^30	-- Lua 5.1, 5.2 to get 1073741824

	x = 1<<30	-- Lua 5.3 to get 1073741824


the difference in unsigned and signed shifting exists only in right-shifts, where the sign bit, which is at the leftmost position, is either kept (signed) or filled with zero or carry bit (unsigned)
On left-shifts no two versions are needed.