Shl

Value = Shl ( Number , Bit )

Value = Number Shl Bit

Seit 3.17

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)
Try i2 = Shl(b1, 16) ' Stops here with Bad Argument
If Error then
  Print Error.Text
Else
  PRINT "   i2="; Hex$(i2)
Endif
i1=550000

See also