lang • shl

Shl

Value = Shl ( Number , Bit )

Returns Number shifted to the left by Bit bits. The sign of Number is kept.

The type of Number may be Byte, Short, Integer, or Long.

The valid range of Bit depends on the type of the Number argument.

Type of Number

Range of Bit
Byte 0...7
Short 0...15
Integer 0...31
Long 0...63

The datatype of the return value is the datatype of Number.

Errors

Message

Description
Type mismatch (6) The datatype of the Number argument is not valid.
Bad argument (20) The Bit argument is out of range.

Examples

Print Bin(11, 32), 11
Print Bin(Shl(11, 2), 32), Shl(11, 2)
Print Bin(Shl(11, 28), 32), Shl(11, 28)
00000000000000000000000000001011        11
00000000000000000000000000101100        44
00110000000000000000000000000000        805306368
Print Bin(-11, 32), -11
Print Bin(Shl(-11, 2), 32), Shl(-11, 2)
Print Bin(Shl(-11, 28), 32), Shl(-11, 28)
11111111111111111111111111110101        -11
11111111111111111111111111010100        -44
11010000000000000000000000000000        -805306368

It may be useful to expand the type of an argument. Use for this CLong, CInt or CShort.

Dim b1 As Byte
Dim i1 As Integer
Dim i2 As Integer

b1 = &H55
' Bad Argument, maximum = 7 for Byte for Integer : s2 = Shl(b1, 8) OR b2
i1 = Shl(CInt(b1), 16)
Print "i1="; Hex$(i1)
i2 = Shl(b1, 16) ' Stops here with Bad Argument
Print "   i2="; Hex$(i2)
i1=550000

See also