Topic: DMD0528

Help File Version: 2.9.4.37

Math Unsigned Shift Right Operator


The Math Shift Right operator ( >>> ) causes the bits in left operand to be shifted to the right by the number of positions specified by the right operand. An Unsigned Right Shift is a logical shift which means that the bits that are shifted off the end are discarded. The bit positions that have been vacated by the Unsigned Right Shift operation are zero-filled.

 

The number of bit positions to shift should be between 1 and the maximum number of bit positions in the left operand. Executing an Unsigned Right Shift with a bit count higher than the number of bit positions in the left operand is not an error but will yield a result of 0. Executing an Unsigned Right Shift by 0 bits has no effect. Executing a Right Shift with a negative value for the bit count is undefined; the result will be 0.

 

Unsigned Integers: assume V0 = 0x1234

 

V1 = V0 >>> 5

 

V1 = 0x1234 >>> 5

 

0000_0000_0000_0000_0001_0010_0011_0100 - initial bit pattern

0000_0000_0000_0000_0000_0000_1001_0001 - after 5th right shift

 

V1 = 0x91

 

One operand is an unsigned integer memory locations, the other is an integer constant.

 

The 16-bit integer is sign-extended to 32-bits when it is loaded into the math stack.

 

The lower 5 bits are shifted out. The remaining 11 bits are shifted into the lowest 11 bit positions. The upper 5 positions are filled with 0's.

 

The result is placed in an unsigned integer memory location.

 

 

Signed Integers: assume D0 = -12345678

 

D1 = D0 >>> 5

 

D1 = -12345678 >>> 5

 

1111_1111_0100_0011_1001_1110_1011_0010 - initial bit pattern

0000_0111_1111_1010_0001_1100_1111_0101 - after 5th right shift

 

D1 = 133831925

 

One operand is an unsigned integer memory locations, the other is an integer constant.

 

The lower 5 bits are shifted out. The remaining 11 bits are shifted into the lowest 11 bit positions. The upper 5 positions are filled with 0's.

 

The result is placed in a signed integer memory location.

 

N1 = N0 >>> 5

 

N1 = -12345 >>> 5

 

1111_1111_1111_1111_1100_1111_1100_0111 - initial bit pattern

0000_0111_1111_1111_1111_1110_0111_1110 - after 5th right shift

 

N1 = -386

 

One operand is an unsigned integer memory locations, the other is an integer constant.

 

The 16-bit integer is sign-extended to 32-bits when it is loaded into the math stack.

 

The lower 5 bits are shifted out. The remaining 11 bits are shifted into the lowest 11 bit positions. The upper 5 positions are filled with 0's.

 

The result is placed in a signed integer memory location.

 

 


See Also:

Add

Subtract

Multiply

Divide

 

Modulus / Remainder

Raise to a Power

 

Less Than

Less than or Equal To

 

Equal To

Not Equal To

 

Greater Than

Greater Than or Equal To

 

Logical AND

Logical OR

 

Bit-wise AND

Bit-wise OR

Bit-wise XOR

 

Shift Left

Shift Right

Unsigned Shift Right

 

Negate

Bit-wise Invert

Logical NOT

 


Related Topics:

MATH - Calculate Expression