Bitwise Unsigned Right Shift (>>>) Expression

Summary

Perform a zero-fill right shift by the specified amount.

Syntax

expression >>> amount

Parameters

expression
Any valid numeric expression.
amount
The amount to shift the bits. The amount can be any valid expression.

Description

The >>> operator computes the value of the expression on the right, and then shifts the bits of the expression on the left by the specified amount. In a bitwise zero-fill right shift operation, the value to shift is converted to its binary representation. For example, the decimal (base 10) number 0 (zero) may be converted to the binary form 0000 and the number 1 (one) may be converted to 0001. The bitwise sign-propagating right shift operation will move each bit to the right by the specified amount. For example, if we shift the base 10 number 4 (four) to the right by 2 (two), the operation looks like:

1
2
3
0100 (4)
--------
0001 (1) // 4 >>> 2

In this case, the base 10 number 1 (one) is produced by shifting the base 10 number 4 (four) to the right by two.

Zero bits are added to the left, and excess bits on the right that were shifted off are discarded.

Differences from JavaScript

Bitwise zero-fill right shift operations are not limited to unsigned 32-bit integers in JS++. Unimplemented In JavaScript, the bitwise zero-fill right shift operation is limited to unsigned 32-bit integers.

Examples

Basic Usage
1
2
3
import System;
 
Console.log(8 >>> 2); // 2
Division by 2 using Bitwise Unsigned Right Shifts
1
2
3
4
5
import System;
 
Console.log(8 >>> 1);  // 4
Console.log(4 >>> 1);  // 2
Console.log(2 >>> 1);  // 1

See Also

External Links

Share

HTML | BBCode | Direct Link