Compartilhar via


Operador << (Visual Basic)

Executa uma aritmética esquerda deslocar em um padrão de bit.

result = pattern << amount

Parts

  • result
    Required. Integral numeric value. The result of shifting the bit pattern. The data type is the same as that of pattern.

  • pattern
    Required. Integral numeric expression. The bit pattern to be shifted. The data type must be an integral type (SByte, Byte, Short, UShort, Integer, UInteger, Long, or ULong).

  • amount
    Required. Numeric expression. The number of bits to shift the bit pattern. The data type must be Integer or widen to Integer.

Comentários

Arithmetic shifts are not circular, which means the bits shifted off one end of the result are not reintroduced at the other end. In an arithmetic left shift, the bits shifted beyond the range of the result data type are discarded, and the bit positions vacated on the right are set to zero.

Para evitar um deslocar por bits mais do que o resultado pode comportar, o Visual Basic mascara o valor de amount com uma máscara de tamanho que corresponde ao tipo de dados de pattern. The binary AND of these values is used for the shift amount. The size masks are as follows:

Data type of pattern

Size mask (decimal)

Size mask (hexadecimal)

SByte, Byte

7

&H00000007

Short, UShort

15

&H0000000F

Integer, UInteger

31

&H0000001F

Long, ULong

63

&H0000003F

If amount is zero, the value of result is identical to the value of pattern. If amount is negative, it is taken as an unsigned value and masked with the appropriate size mask.

Arithmetic shifts never generate overflow exceptions.

ObservaçãoObservação

The << operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. Se o seu código utiliza este operador em uma classe ou estrutura, certifique-se de que você compreenda seu comportamento redefinido. For more information, see Procedimentos de operador (Visual Basic).

Exemplo

O exemplo a seguir usa a <<deoperador para executar cálculos aritméticos deixado turnos nos valores integrais. The result always has the same data type as that of the expression being shifted.

Dim pattern As Short = 192
' The bit pattern is 0000 0000 1100 0000.
Dim result1, result2, result3, result4, result5 As Short
result1 = pattern << 0
result2 = pattern << 4
result3 = pattern << 9
result4 = pattern << 17
result5 = pattern << -1

Os resultados do exemplo anterior são os seguintes:

  • result1 is 192 (0000 0000 1100 0000).

  • result2 is 3072 (0000 1100 0000 0000).

  • result3 is -32768 (1000 0000 0000 0000).

  • result4 is 384 (0000 0001 1000 0000).

  • result5é 0 (deslocadas 15 casas à esquerda).

The shift amount for result4 is calculated as 17 AND 15, which equals 1.

Consulte também

Referência

Operadores Bit Shift (Visual Basic)

Operadores de atribuição (Visual Basic)

Operador <<= (Visual Basic)

Precedência de operadores no Visual Basic

Operadores listados por Funcionalidade (Visual Basic)

Conceitos

Operadores aritméticos em Visual Basic