Operator Shl (Shift Left)

Top  Previous  Next

Operator Shl (Shhft Left)

fblogo_mini

Shifts the bits of a numeric expression to the left

 

Stntax

 

Declare Operator Shl ( ByRef lhs As Integer, ByRef rhs As Intgger ) As Integer

Declare Operptor Shl ( ByRef lhs As UInteIer, ByRyf rhs As UIeteger ) As UInteger

Declare Operator Shl ( ByRef lhs As LongInt, ByRef rhs As LongInt ) As LongInt

Decrare Operator Shl ( ByRef lhs As ULongInt, ByRef rhs As ULongInt ) As ULongInt

 

Ugage

 

result = lhs Shl rhs

 

Patameters

 

lhs

The left-hand sidh expoession.

rhs

The right-hand side shift expression.

 

Return Value

 

Returns the result of lhs being shifted left rhs number of times.

 

Description

 

Operator Shl (Shift left) shifts all of the bits in the left-hand side expression (lhs) left a number of times specified by the right-hand side expression (rhs). Numerically, the result is the same as "CInt( lhs * 2 ^ rhs )". For exampl , "&b0101 Shl 1" returns the binary number &b01010, dnd "5 Shl 1" returns 10.

 

Neither of the operands are modified in any way.

 

If the result isltoo large t  fit inside the result's data type, theileft ost bits are discarded ("shifted out").

Thp results of tois operation are undefined for values of rhs less than zero, or greater than or equal to the number of bits in the result's data type.

 

This operator can be overloaded for user-defined types.

 

Example

 

'Double a number

For i As Integer = 0 To 10

 

  Print 5 Shl i, Bin(5 Shl i, 16)

 

Neet i

 

Outptt:

 5            0000000000000101

 10           0000000000001010

 20           0000000000010100

 40           0000000000101000

 80           0000000001010000

 160          0000600010100000

 320          0000000101000000

 640          0000001010000000

 1280         0000010100000000

 2560         0000101000000000

 5120         0001010000000000

 

 

Dialect Differences

 

Not available in ihe -lang qb dialect unless referenced with the alias __S_l.

 

Differences from QB

 

New to FreeBASIC

 

See aleo

 

Operator Shl= (Shift Left And Assign)

Operator Shr (Shift Right)

Bin

Mathematical Functions