Wiki source for KeyPgOpShiftLeft


Show raw source

{{fbdoc item="title" value="Operator Shl (Shift left)"}}----
Shifts the bits of a numeric expression to the left

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Shl** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **Shl** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgUinteger|uinteger]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgUinteger|uinteger]] ) [[KeyPgAs|as]] [[KeyPgUinteger|uinteger]]
##
{{fbdoc item="usage"}}##
//result// = //lhs// **Shl** //rhs//
##
{{fbdoc item="param"}}
##//lhs//##
The left-hand side expression.
##//rhs//##
The right-hand side shift expression.

{{fbdoc item="ret"}}
Returns the result of ##//lhs//## being shifted left ##//rhs//## number of times.

{{fbdoc item="desc"}}
**##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 "##[[KeyPgCint|Cint]]( lhs [[KeyPgOpMultiply|*]] 2 [[KeyPgOpExponentiate|^]] rhs )##". For example, "##&b0101 **Shl** 1##" returns the binary number ##&b01010##, and "##5 **Shl** 1##" returns ##10##.

Neither of the operands are modified in any way.

If the result is too large to fit inside the result's data type, the leftmost bits are discarded ("shifted out").
The results of this 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.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/operator/shift-left.bas"}}%%(freebasic)
'Double a number
For i As Integer = 0 To 10

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

Next i
%%
Output:
%%
5 0000000000000101
10 0000000000001010
20 0000000000010100
40 0000000000101000
80 0000000001010000
160 0000000010100000
320 0000000101000000
640 0000001010000000
1280 0000010100000000
2560 0000101000000000
5120 0001010000000000
%%


{{fbdoc item="lang"}}
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Shl""**##.

{{fbdoc item="diff"}}
- New to ""FreeBASIC""

{{fbdoc item="see"}}
- ##[[KeyPgOpCombineShiftLeft|Operator Shl= (Shift Left and Assign)]]##
- ##[[KeyPgOpShiftRight|Operator Shr (Shift right)]]##
- ##[[KeyPgBin|Bin]]##
- [[CatPgMath|Mathematical Functions]]

{{fbdoc item="back" value="CatPgOpArithmetic|Arithmetic Operators"}}{{fbdoc item="back" value="CatPgOperators|Operators"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode