Logical (unsigned) shift right operator - shifts bits right, filling with zeros.
Keywords
Parameters & Returns
Parameters
This function takes no parameters.
Returns
Int
Quick Summary
Logical (unsigned) shift right operator - shifts bits right, filling with zeros.
Technical Exegesis...
Syntax is value ShrU count. Shifts the 32 bits of the value right by count positions and fills the top with zeros, so the result is never negative for a count of 1 or more: -1 ShrU 28 is 15. Shr instead copies the sign bit down (an arithmetic shift), so -1 Shr 28 is still -1.
Use ShrU to pull fields out of a full 32-bit value (colours, packed data, CPU instructions in an emulator) without masking off the sign afterwards. The count is taken modulo 32 (0 to 31), as the CPU does.
Syntax is value ShrU count. Shifts the 32 bits of the value right by count positions and fills the top with zeros, so the result is never negative for a count of 1 or more: -1 ShrU 28 is 15. Shr instead copies the sign bit down (an arithmetic shift), so -1 Shr 28 is still -1.
Use ShrU to pull fields out of a full 32-bit value (colours, packed data, CPU instructions in an emulator) without masking off the sign afterwards. The count is taken modulo 32 (0 to 31), as the CPU does.
On the web, a count of 0 gives the value as unsigned: -1 ShrU 0 is 4294967295 there, but -1 on desktop, Linux and the PlayStation.
Example
Example.bam
Local colour:Int = $FF8040C0
Print colour ShrU 24 ; 255 (the alpha) - Shr would give -1
Print (colour ShrU 16) BitAnd 255 ; 128 (the red)