> For the complete documentation index, see [llms.txt](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/6.-aritmetica/operacoes-de-deslocamento/deslocar-gera-novos-bits.md).

# Deslocar Gera Novos Bits

Uma operação de deslocamento move os bits para uma extremidade do número e precisa gerar novos bits na outra extremidade.

Deslocar para a esquerda um bit deve gerar um novo bit menos significativo. Ele sempre insere um zero ali. Isso é equivalente a multiplicar pela potência de 2 correspondente. Por exemplo,

```c
5 << 3     é equivalente a   5 * 2*2*2
-10 << 4   é equivalente a   -10 * 2*2*2*2
```

O significado de deslocar para a direita depende se o tipo de dado é com sinal ou sem sinal (veja [Tipos Com ou Sem Sinal](#user-content-fn-1)[^1]). Para um tipo de dado com sinal, ele realiza um “deslocamento aritmético,” que mantém o sinal do número inalterado ao duplicar o bit de sinal. Para um tipo de dado sem sinal, ele realiza um “deslocamento lógico,” que sempre insere zeros no bit mais significativo.

Em ambos os casos, deslocar para a direita um bit é uma divisão por dois, arredondando em direção ao infinito negativo. Por exemplo,

```c
(unsigned) 19 >> 2 ⇒ 4
(unsigned) 20 >> 2 ⇒ 5
(unsigned) 21 >> 2 ⇒ 5
```

Para um operando esquerdo negativo `a`, `a >> 1` não é equivalente a `a / 2`. Ambos dividem por 2, mas `‘/’` arredonda em direção a zero.

A contagem de deslocamento deve ser zero ou maior. Deslocar por um número negativo de bits produz resultados dependentes da máquina.

[^1]: Capítulo pendente de tradução


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/6.-aritmetica/operacoes-de-deslocamento/deslocar-gera-novos-bits.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
