Global Information Lookup Global Information

Arithmetic shift information


A right arithmetic shift of a binary number by 1. The empty position in the most significant bit is filled with a copy of the original MSB.
A left arithmetic shift of a binary number by 1. The empty position in the least significant bit is filled with a zero.
Arithmetic shift operators in various programming languages and processors
Language or processor Left Right
ActionScript 3, Java, JavaScript, Python, PHP, Ruby, C, C++,[1]D, C#, Go, Julia,
Rust (signed types only)[2],
Swift (signed types only)[note 1]
<< >>
Ada Shift_Left [3] Shift_Right_Arithmetic
Kotlin shl shr
Fortran SHIFTL SHIFTA [note 2]
Standard ML << ~>>
Verilog <<< >>> [note 3]
OpenVMS macro language @[note 4]
Scheme arithmetic-shift[note 5]
Common Lisp ash
OCaml lsl asr
Haskell Data.Bits.shift[note 6]
VHDL sla[note 7] sra
Assembly: Z80 SLA[5] SRA
Assembly: x86 SAL SAR
Assembly: 68k ASL ASR
Assembly: RISC-V sll, slli[6] sra, srai

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 (usually the sign bit in signed integer 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.[7]

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.[8]

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.[9] 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.

  1. ^ "Bit manipulation - Dlang Tour". tour.dlang.org. Retrieved 2019-06-23.
  2. ^ "Operator Expressions: Arithmetic and Logical Binary Operators". doc.rust-lang.org. Retrieved 2022-11-13.
  3. ^ "Annotated Ada 2012 Reference Manual".
  4. ^ HP 2001.
  5. ^ "Z80 Assembler Syntax".
  6. ^ "The RISC-V Instruction Set Manual, Volume I: Unprivileged ISA" (PDF). GitHub. 2019-12-13. pp. 18–20. Archived (PDF) from the original on 2022-10-09. Retrieved 2021-08-07.
  7. ^ Thomas R. Cain and Alan T. Sherman. "How to break Gifford's cipher". Section 8.1: "Sticky versus Non-Sticky Bit-shifting". Cryptologia. 1997.
  8. ^ Steele Jr, Guy. "Arithmetic Shifting Considered Harmful" (PDF). MIT AI Lab. Archived (PDF) from the original on 2022-10-09. Retrieved 20 May 2013.
  9. ^ Hyde 1996, § 6.6.2.2 SAR.


Cite error: There are <ref group=note> tags on this page, but the references will not show without a {{reflist|group=note}} template (see the help page).

and 19 Related for: Arithmetic shift information

Request time (Page generated in 0.8252 seconds.)

Arithmetic shift

Last Update:

In computer programming, an arithmetic shift is a shift operator, sometimes termed a signed shift (though it is not restricted to signed operands). The...

Word Count : 1716

Bitwise operation

Last Update:

following way: In an arithmetic shift, the bits that are shifted out of either end are discarded. In a left arithmetic shift, zeros are shifted in on the right;...

Word Count : 3812

Arithmetic logic unit

Last Update:

In computing, an arithmetic logic unit (ALU) is a combinational digital circuit that performs arithmetic and bitwise operations on integer binary numbers...

Word Count : 2922

Logical shift

Last Update:

positions a given value shall be shifted, such as shift left by 1 or shift right by n. Unlike an arithmetic shift, a logical shift does not preserve a number's...

Word Count : 627

Arithmetic

Last Update:

Arithmetic is an elementary branch of mathematics that studies numerical operations like addition, subtraction, multiplication, and division. In a wider...

Word Count : 16355

Circular shift

Last Update:

known as a circular shift, is a bitwise operation that shifts all bits of its operand. Unlike an arithmetic shift, a circular shift does not preserve a...

Word Count : 986

Shift

Last Update:

circuit implementing bit shifts Bit shift, an operation treating a value as a sequence of binary digits Arithmetic shift Circular shift, often used in cryptography...

Word Count : 492

Shift operator

Last Update:

hypergroup. Arithmetic shift Logical shift Clock and shift matrices Finite difference Translation operator (quantum mechanics) Weisstein, Eric W. "Shift Operator"...

Word Count : 1452

Binary number

Last Update:

operations may be used as arithmetic short-cuts, and may have other computational benefits as well. For example, an arithmetic shift left of a binary number...

Word Count : 6665

Bitwise operations in C

Last Update:

compilers will perform an arithmetic shift, causing the blank to be filled with the set sign bit of the left operand. Right shift can be used to divide a...

Word Count : 1863

LEB128

Last Update:

only necessary if the implementation of >>= uses a logical shift rather than an arithmetic shift for a signed left operand */ if (negative) value |= (~0...

Word Count : 1438

Left shift

Last Update:

Left shift may refer to: Left shift (medicine), a medical term similar to blood shift Logical left shift, a computer operation Arithmetic left shift, a...

Word Count : 96

ASR

Last Update:

aquifer Airport surveillance radar Asr (radar), an Iranian radar system Arithmetic shift right, a computer instruction Answer-seizure ratio, the percentage...

Word Count : 284

Number theory

Last Update:

(or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions...

Word Count : 11159

WD16

Last Update:

lower-numbered register. 32 bit values are used by MUL, DIV and some rotate and arithmetic shift instructions. Floating point values are 48 bits long and can only be...

Word Count : 2874

Software portability

Last Update:

implementation defined behaviour (e.g. right shifting a signed integer in C can do a logical or an arithmetic shift). Operating system functions or third party...

Word Count : 925

Arithmetic coding

Last Update:

Arithmetic coding (AC) is a form of entropy encoding used in lossless data compression. Normally, a string of characters is represented using a fixed number...

Word Count : 5405

Binary GCD algorithm

Last Update:

algorithm uses simpler arithmetic operations than the conventional Euclidean algorithm; it replaces division with arithmetic shifts, comparisons, and subtraction...

Word Count : 2028

Sign extension

Last Update:

eax, 1234 will clear the upper 32 bits of the rax register. Arithmetic shift and logical shift Mano, Morris M.; Kime, Charles R. (2004). Logic and Computer...

Word Count : 456

PDF Search Engine © AllGlobal.net