| rdfs:comment
| - A shift operator is used to move the binary flags in a certain direction along the binary digits. In NWScript, the shift operators are <<, >>, and >>>. All shift operators use the integer data type both for the binary field whose flags are being shifted and for the number of places the flags are shifted. The binary field is entered to the left of the shift operator, and the number of places is entered to the right of the shift operator. The number of places is interpreted by machine code modulo 32 (thus shifts are from 0 to 31 places, values outside the range are interpreted as their remainder when divided by 32). The binary field in NWScript consists of 32 bits. No shift in NWScript is circular, thus binary flags shifted outside the binary field are lost.
|
| abstract
| - A shift operator is used to move the binary flags in a certain direction along the binary digits. In NWScript, the shift operators are <<, >>, and >>>. All shift operators use the integer data type both for the binary field whose flags are being shifted and for the number of places the flags are shifted. The binary field is entered to the left of the shift operator, and the number of places is entered to the right of the shift operator. The number of places is interpreted by machine code modulo 32 (thus shifts are from 0 to 31 places, values outside the range are interpreted as their remainder when divided by 32). The binary field in NWScript consists of 32 bits. No shift in NWScript is circular, thus binary flags shifted outside the binary field are lost. The left shift << shifts all binary flags to the left the given number of places, appending zeroes for the binary digits that no longer have a flag. This has a mathematical effect of multiplying the number by a power of two. The arithmetic (signed) right shift >>> shifts all binary flags to the right the given number of places. The first bit (called the master bit) determines which binary digit value is used for all the leftmost digits that no longer have a flag. This has a mathematical effect of dividing a number by a power of two and rounding down a remainder. The other right shift >> is designed around the ones' complement system. It does not shift the standard NWScript bit flags, but rather, makes the right shifting of negative numbers parallel the right shifting of positive numbers. For positive numbers, both the arithmetic right shift and the >> right shift yield the same value. For negative numbers, the two shifts can be off by as much as one, as the >> right shift is the mathematical equivalent of dividing by a power of two and truncating the remainder.
|