operator
<
<
{
associativity
precedence
}
Declarations
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The <<
operator performs a smart shift, which defines a result for a
shift of any value.
- Using a negative value for
rhs
performs a right shift usingabs(rhs)
. - Using a value for
rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero. - Using any other value for
rhs
performs a left shift onlhs
by that amount.
The following example defines x
as an instance of UInt8
, an 8-bit,
unsigned integer type. If you use 2
as the right-hand-side value in an
operation on x
, the value is shifted left by two bits.
let
x
:
UInt8
=
30
// 0b00011110
let
y
=
x
<
<
2
// y == 120 // 0b01111000
If you use 11
as rhs
, x
is overshifted such that all of its bits
are set to zero.
let
z
=
x
<
<
11
// z == 0 // 0b00000000
Using a negative value as rhs
is the same as performing a right shift
with abs(rhs)
.
let
a
=
x
<
<
-
3
// a == 3 // 0b00000011
let
b
=
x
>
>
3
// b == 3 // 0b00000011
Parameters:
lhs: The value to shift.
rhs: The number of bits to shift lhs
to the left.
Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger
10 inherited items hidden. (Show all)
Returns the result of shifting a value's binary representation the specified number of digits to the left.
The
<<
operator performs a smart shift, which defines a result for a shift of any value.rhs
performs a right shift usingabs(rhs)
.rhs
that is greater than or equal to the bit width oflhs
is an overshift, resulting in zero.rhs
performs a left shift onlhs
by that amount.The following example defines
x
as an instance ofUInt8
, an 8-bit, unsigned integer type. If you use2
as the right-hand-side value in an operation onx
, the value is shifted left by two bits.If you use
11
asrhs
,x
is overshifted such that all of its bits are set to zero.Using a negative value as
rhs
is the same as performing a right shift withabs(rhs)
.Parameters: lhs: The value to shift. rhs: The number of bits to shift
lhs
to the left.Declaration
func
<
<
<
Other
>
(
lhs
:
Self
,
rhs
:
Other
) -
>
Self
where
Other
:
BinaryInteger
Declared In
FixedWidthInteger