Shl Function

Purpose

Shifts a bit pattern left.

Syntax

Shl(m, n)

Shl&(m, n)

Shl%(m, n)

Shl|(m, n)

Shl8(m, n)

m Shl n

m Shl8 n

Shl v, n

m, n:integer expression
v:variable

Description

Shl(m, n) and Shl% shifts the bit pattern of a 32-bit integer expressions m, n places left (Shl = SHift Left) and, optionally, stores the new value in a variable. Shl&(m, n) and Shl|(m, n) shift the bit pattern of a 16-bit or an 8-bit integer expression m respectively, n places left. Shl8 is used to shift a Large integer.

The operators Shl and Shl8 perform a left shift on an integer and Large, respectively.

Shl v, n assignment shifts the value in v by n and returns the value in v. The type of the operation is determined by the type of variable v.

Example

Local l%, l|

Debug.Show

Trace Bin$(202, 16)          // Prints 0000000011001010

Trace Bin$(Shl(202, 4), 16// Prints 0000110010100000

l% = Shl(202, 4)

Trace l%                     // Prints 3232

Trace Bin$(202, 16)          // Prints 0000000011001010

Trace Bin$(Shl%(202, 4), 16) // Prints 0000110010100000

l% = Shl%(202, 4)

Trace l%                     // Prints 3232

Trace Bin$(202, 8)           // Prints 11001010

Trace Bin$(Shl|(202, 4), 8// Prints 10100000

l| = Shl|(202, 4)

Trace l|                     // Prints 160

Remarks

m<< n is synonymous with Shl(m, n) and can be used instead.

As long as the result of the shift does not exceed the given width, Shl(m, n) is equivalent to a multiplication of m with 2^n.

Example to shift bits

Shl(63, 2) or 63 Shl 2

63 it binary: 0000 0000 0000 0000 0000 0000 0011 1111

Shift left: 0000 0000 0000 0000 0000 0000 0111 1110

Shift left : 0000 0000 0000 0000 0000 0000 1111 1100

Result is 124 = 63 * 4 = 63 * 2^2

Shl(-1, 4) or -1 Shl 4

-1 is binary: 1111 1111 1111 1111 1111 1111 1111 1111

Shift: 1111 1111 1111 1111 1111 1111 1111 1110

Shift: 1111 1111 1111 1111 1111 1111 1111 1100

Shift: 1111 1111 1111 1111 1111 1111 1111 1000

Shift: 1111 1111 1111 1111 1111 1111 1111 0000

Result is -16 = -1 * 16 = -1 * 2^4

See Also

Shr Rol, Ror, <<, >>

{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}