09-11-2022, 12:51 PM
(09-08-2022, 10:47 PM)TDarcos Wrote: Shift is like a bulldozer pushing the bits off the edge. The bits are replaced by 0 for non-negative numbers and 1 for negative numbers.
Rotate is like putting the bits on a conveyor belt or a lazy Susan. the bits that roll off come back around.
That's a great clarification that I either missed or wasn't stated elsewhere. A right shifted negative number will end at -1, the Most Significant Bits (MSB) being filled by 1s. I'll have to play with the action for _UNSIGNED types when I have more time.
Code: (Select All)
a% = -20
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHR(a%, 2)
PRINT _BIN$(a%), a%
I also note that with a negative value, it will put the 1s on the MSB and 0s on the LSB, depending on the shift direction. Which keeps the action working as a multiple of 2, regardless of the shift direction. Enough left shifts of a negative will, however, overflow the variable type container to 0.
Code: (Select All)
a% = -1
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
a% = _SHL(a%, 2)
PRINT _BIN$(a%), a%
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: