SHL (Shift Left)
Shifts bits left by N positions, filling right with zeros. Equivalent to multiply by 2^N.
The SHL (Shift Left) function shifts the bits of the input value to the left by a specified number of positions. Vacated bit positions on the right are filled with zeros. Bits shifted past the leftmost position are lost. Each left shift by 1 position is equivalent to multiplying by 2. SHL is used for bit manipulation, creating bitmasks, multiplying by powers of 2, and protocol encoding.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN | ANY_BIT | Value to shift |
| N | INT | Number of bit positions to shift left |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | ANY_BIT | Shifted result |
Ladder Logic Example
// Ladder Logic - SHL (Create Bitmask) // // |----[SHL]----| // | IN: 16#0001 | // | N: Bit_Position | // | OUT: Bit_Mask |
Structured Text Example
Bit_Mask := SHL(16#0001, Bit_Position); // Position 0: 0000_0001 // Position 3: 0000_1000 // Position 7: 1000_0000 // Quick multiply by 8: Result := SHL(Value, 3); // Value * 2^3 = Value * 8
20 Production-Ready Ladder Logic Templates
Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.
Platform-Specific Implementation
Siemens (TIA Portal)
Use SHL instruction in TIA Portal.
Allen-Bradley (Studio 5000)
Use BSL (Bit Shift Left) instruction for single-bit shifts, or SHL for word-level.
CODESYS
Use SHL() function in ST.
Common Applications
- Bitmask creation
- Fast multiplication by powers of 2
- Protocol data packing
- Status word construction
- LED pattern generation
Frequently Asked Questions
What is SHL (Shift Left) in PLC programming?
Shifts bits left by N positions, filling right with zeros. Equivalent to multiply by 2^N. The SHL (Shift Left) function shifts the bits of the input value to the left by a specified number of positions. Vacated bit positions on the right are filled with zeros.
What are common applications of SHL (Shift Left)?
SHL (Shift Left) is commonly used for: Bitmask creation, Fast multiplication by powers of 2, Protocol data packing, Status word construction, LED pattern generation.
How do I use SHL (Shift Left) in different PLC platforms?
Siemens: Use SHL instruction in TIA Portal. Allen-Bradley: Use BSL (Bit Shift Left) instruction for single-bit shifts, or SHL for word-level. CODESYS: Use SHL() function in ST.
Related Function Blocks
SHR (Shift Right)
Shifts bits right by N positions. Equivalent to integer division by 2^N.
View Reference →ROL (Rotate Left)
Rotates bits left; bits shifted out the left wrap around to the right.
View Reference →MOVE (Data Move)
Copies a value from source to destination for any data type.
View Reference →SWAP (Byte Swap)
Reverses byte order of a word value for endianness conversion.
View Reference →Stop Writing Ladder Logic From Scratch
Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.
Instant download - 30-day money-back guarantee - Use on unlimited projects