TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
>> operator is the bitwise right shift operator in Go. It shifts the binary representation of the left operand to the right by the number of bit positions specified by the right operand.
Operand Constraints
- Left Operand (
x): Must be of an integer type (signed or unsigned) or an untyped constant representable as an integer. - Right Operand (
n): Must be of an integer type or an untyped constant representable as an unsigned integer. Shifting by a negative count results in a compile-time error or a runtime panic.
Shift Mechanics
Go determines the type of right shift to perform based on the underlying type of the left operand. There is no separate logical right shift operator (like>>> in Java); instead, Go uses the type system to dictate behavior.
1. Unsigned Integers (Logical Right Shift)
If the left operand is an unsigned integer (e.g.,uint, uint8, uint16), Go performs a logical right shift. The bits are shifted to the right, and the vacated Most Significant Bits (MSBs) on the left are filled with zeros (0).
2. Signed Integers (Arithmetic Right Shift)
If the left operand is a signed integer (e.g.,int, int8, int16), Go performs an arithmetic right shift. The bits are shifted to the right, but the vacated MSBs are filled with a copy of the original sign bit. This preserves the sign of the number (Two’s complement representation).
- If the number is positive (sign bit
0), vacated bits are filled with0. - If the number is negative (sign bit
1), vacated bits are filled with1.
Mathematical Equivalence
Mathematically, shifting an integerx right by n positions is equivalent to integer division by , rounded towards negative infinity:
Out-of-Bounds Shifts
If the right operandn is greater than or equal to the size of the left operand in bits:
- For unsigned integers, the result is always
0. - For signed integers, the result is
0if the original number was positive, and-1(all bits set to1) if the original number was negative.
Master Go with Deep Grasping Methodology!Learn More





