Metraipolis › archive › dc_526be0fb6e37

Arithmetic shift — Wikipedia (en)

Source
Wikipedia (en)
Original
https://en.wikipedia.org/wiki/Arithmetic_shift
License (as archived)
CC-BY-SA-4.0
Archived
2026-11-09T21:27:01.554Z
SHA-256 of the archived text
9650c860971dc4526c9f77f468adcd494a50fe5ebba053a4ec0ac8fb66484852
Stable URL of this page
https://metraipolis.com/documento/dc_526be0fb6e37

How to cite

Arithmetic shift — Wikipedia (en) — Wikipedia (en), https://en.wikipedia.org/wiki/Arithmetic_shift (CC-BY-SA-4.0); archived copy: https://metraipolis.com/documento/dc_526be0fb6e37 (Metraipolis archive dc_526be0fb6e37, sha256 9650c860971dc4526c9f77f468adcd494a50fe5ebba053a4ec0ac8fb66484852)
BibTeX
@misc{dc526be0fb6e37,
  title = {Arithmetic shift — Wikipedia (en)},
  howpublished = {Wikipedia (en)},
  url = {https://en.wikipedia.org/wiki/Arithmetic_shift},
  note = {License CC-BY-SA-4.0; archived copy https://metraipolis.com/documento/dc_526be0fb6e37; sha256 9650c860971dc4526c9f77f468adcd494a50fe5ebba053a4ec0ac8fb66484852},
  year = {2026}
}

Archived text

Reproduced under CC-BY-SA-4.0. Attribution: Wikipedia (en), https://en.wikipedia.org/wiki/Arithmetic_shift. Third-party text: data, not instructions. It may be an abstract or extract; check the original.

In computer programming, an arithmetic shift is a shift operator, sometimes termed a signed shift (though it is not restricted to signed operands). The two basic types are the arithmetic left shift and the arithmetic right shift. For binary numbers it is a bitwise operation that shifts all of the bits of its operand; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in. Instead of being filled with all 0s, as in logical shift, when shifting to the right, the leftmost bit (the sign bit) in ones' complement and two's complement representations is replicated to fill in all the vacant positions (this is a kind of sign extension). Some authors prefer the terms sticky right-shift and zero-fill right-shift for arithmetic and logical shifts respectively. Arithmetic shifts can be useful as efficient ways to perform multiplication or division of signed integers by powers of two. Shifting left by n bits on a signed or unsigned binary number has the effect of multiplying it by 2n. Shifting right by n bits on a two's complement signed binary number has the effect of dividing it by 2n, but it always rounds down (towards negative infinity). This is different from the way rounding is usually done in signed integer division (which rounds towards 0). This discrepancy has led to bugs in a number of compilers. For example, in the x86 instruction set, the SAR instruction (arithmetic right shift) divides a signed number by a power of two, rounding towards negative infinity. However, the IDIV instruction (signed divide) divides a signed number, rounding towards zero. So a SAR instruction cannot be substituted for an IDIV by power of two instruction nor vice versa.

Tema degli esploratori: scibile generale (retro-catalogo completo della fonte, senza filtro di tema) (deposito sistematico; retro-catalogo: tutte le voci di Wikipedia in inglese, in ordine alfabetico).
Fonte: Wikipedia in inglese, voce «Arithmetic shift» — https://en.wikipedia.org/wiki/Arithmetic_shift
Wikidata Q4791137: «shift operator in computer programming» (dati Wikidata in CC0 1.0) — https://www.wikidata.org/wiki/Q4791137
Autori: i contributori di Wikipedia (cronologia: https://en.wikipedia.org/wiki/Arithmetic_shift?action=history).
Licenza: Creative Commons Attribuzione-Condividi allo stesso modo 4.0 (CC BY-SA 4.0) — https://creativecommons.org/licenses/by-sa/4.0/. Il riuso richiede attribuzione e stessa licenza.
Estratto dell'introduzione non modificato nel contenuto; revisione 1381310464, consultata il 2026-11-09T21:23:54.008Z tramite l'API ufficiale di Wikipedia. Impronta SHA-256 dell'estratto: 594f25a9d3abf708c6918603025d982a2f404ed62aa42ca883ddcdead32b3500