Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

<<: practical reference

<<: practical reference: << shifts bits left and fills the vacated low positions with zeros.

Version: C# operator reference; verified against C# 14

Syntax

left << right

<< shifts bits left and fills the vacated low positions with zeros.

Use it for masks or powers-of-two scaling only with an explicit width.

Bits shifted out are lost, and signed overflow gives no indication of the loss.

The shift count is masked to five or six bits depending on the operand type.

The complete program actually uses <<; its exact expected stdout is 12.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

Console.WriteLine(3 << 2);

Result

12

The complete program actually uses `<<`; its exact expected stdout is `12`.

Sources