Talk:Arithmetic shift

message: When multiplying a negative number written using the one's complement convention, 1, and not 0, should be inserted into the LSB. A clear example of this is 1101 (-2). When left-shifted as described in the article, it'd become 1010 (-5). However, if 1 is put into the LSB, it becomes 1011(-4), the correct answer. So actually, when using one's complement, the signal bit should be reinserted into the LSB after the shift. Budsbd 14:30, 6 March 2007 (UTC)
thread_title:  One's Complement 

message: I added a footnote on how shifts work in Scheme, as I think it is interesting to show that Shifts do not have to be operators and that a hybrid approach is possible (shift left, right and in any way depending on the operator). --88.217.68.206 (talk) 23:44, 18 May 2008 (UTC)
thread_title:  Shift Functions and Signed Arguments 

message: The suggested transition from "older ones' complement architectures to newer two's complement architectures" is not historically correct; the first working digital computer (Zuse Z3) did use the 2's complement.  — Preceding unsigned comment added by Towopedia (talk • contribs) 15:41, 6 September 2012 (UTC)
thread_title:  Complement 

message: The arithmetic left shift diagram appears to be incorrect.    It shows the second-most-significant bit being copied into the most-signficant bit.  In C (C99) and C++ (11) the result of left shifting a negative signed integral type is undefined behavior.  C and C++ can thus be said to have no arithmetic left shift; only logical.
However, in the abstract sense, the most-significant bit should be preserved (+3 becomes +6 and -2 becomes -4). An overflow happens if the most-significant bit is different from any of the N next most significant bits, whether positive or negative.  For the diagram to apply to the abstract logical situation, all those bits disappear and MSB remains the same.  Anything else is a technical detail dependent on the platform or language.  Casu Marzu (talk) 17:51, 30 September 2013 (UTC)
thread_title:  Left shift not correct? 

message: The first pic & its caption (http://en.wikipedia.org/wiki/File:Rotate_left_logically.svg) doesn't go with the text in the Main section of Arithmetic Shift.
Please
*remove the first picture
or
*change its caption stating that it is infact a logic shift operation and is given to differentaite between the two shifts
The caption says "A left arithmetic shift of a binary number by 1..." but it is seen as a "logical shift" as the new bit is filled with zero and not the replicated last bit.  — Preceding unsigned comment added by 122.172.182.194 (talk) 05:36, 27 October 2013 (UTC)
thread_title:  The first picture depicts LOGICAL SHIFT in ARITHMETIC SHIFT 

message: MIPS lacks a sla operator, but is listed as having one 67.252.63.253 (talk) 04:03, 16 December 2015 (UTC)
thread_title:  MIPS lacks a Shift Left Arithmetic operator 

message: This section is supposed to be about arithmetic shift vs multiplication, but then talks about arithmetic shift vs logical shift.  As far as I know, arithmetic and logical left shift are identical operations, so I'm not sure what this section is talking about.
https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift says "Therefore, the logical and arithmetic left-shifts are exactly the same."
How can the "MSB be preserved" when the MSB is destroyed by the shift?? — Omegatron (talk) 00:19, 5 December 2018 (UTC)
thread_title:  Arithmetic vs logical vs multiplication 

message: A funnel shift (or double shift in the x86 instruction set) is the shift of two concatenated bit fields. This is useful for unaligned bit streams. I don't find any mentioning of this in Wikipedia. Should it be added here or made as a separate article? Agnerf (talk) 08:51, 4 April 2021 (UTC)
thread_title:  Funnel shift 

message: I added a fact tag to
> Logical left shifts are also equivalent, except multiplication and arithmetic shifts may trigger arithmetic overflow whereas logical shifts do not
In Intels, RISC-V, and the M68K, logical and arithmetic left shifts are equivalent *including* the flags. I'm not sure what the source for this statement was. 69.121.57.177 (talk) 14:39, 13 August 2023 (UTC)
replies: text: Not only that, all the rest of the text makes no mention of "flags" at all and is comparing the results, which are identical. I'm sure there are lots of ways to change what flags are triggered and you can't just split them into "arithmetic" and "logical". Spitzak (talk) 17:08, 13 August 2023 (UTC)
thread_title:  Logical/arithmetic left equivalence 

message: Most of the entries under "left" in this table are incorrect, as they list logical left shift operators and mnemonics on systems that have no arithmetic left shift.
Instead they should probably either list "none", or clearly identify that these are logical left shifts or somehow note that they are synonymous with arithmetic left shifts. 69.121.57.177 (talk) 14:41, 13 August 2023 (UTC)
replies: text: Found the same thing: The information given for C language in this table is incorrect. For unsigned types shift right (>>) operator is "logical shift" and for signed types the behavior is implementation defined (e.g. depends on CPU and/or compiler). It can be "arithmetic shift" but it doesn't have to. 84.253.48.217 (talk) 13:21, 1 February 2024 (UTC)
thread_title:  Arithmetic shift operators in various programming languages and processors 

message: When shifting right a two's complement number the sign bit is shifted in. Therefore the number of sign bits increases. This is one way to see it.
This is not "visible" for positive values, where the sign bit(s) is 0. And  each 1 bit in position [n] (pos [0] is the rightmost) would represent 2exp(n). A 0 bit gives no added value.
But for negative values the increasing number of sign bits, all those except for the leftmost "real" single sign bit, still (or also) carry the integer weights. For negative values a 0 would in pos [n] mean (-2exp(n))-1. A 1 or "sign" bit gives no added value. 
In other words, the increasing number of sign bits with a right shift of a two's complement would carry this "double meaning" as sign bits or "inverted" bits. And that these increasing number of sign bits don't stand in the way for the value. I guess that's the magic og two's complement.
These leftmost "value" bits, being 1 for negative and 0 for zero or positive values, all they state is that "there is nothing here".
So a shift right by 8 bits always is the same as divide by 2exp(8)=256.
Is this worth mentioning in the article? And in case, how should one say all this "in one sentence"? Or is it there already? Øyvind Teig (talk) 09:46, 18 May 2024 (UTC)
replies: text: This is already talked about over and over and over in this article. And right shift by 8 is floor((x/256.0)), not x/256, which is exactly what all your convoluted description of the sign bit amounts to. Spitzak (talk) 18:14, 19 May 2024 (UTC)
replies: text: Thank you. I am still not able to see where this is discussed in the article. Please give an example. Plus, x >> y = floor(x/pow(2,y)) is correct, but most often not used since we are talking about integer division with integer results, as I was. And the connection of this floor definition with my "convoluted" description I also fail to understand. I did try to repeat points from different angles, which to the best of my understanding should be acceptable on a the talk page, "If in doubt, make the extra effort so that other people understand you. Being friendly is a great help." Øyvind Teig (talk) 21:16, 20 May 2024 (UTC)
thread_title:  Two's complement "double meaning" of MSBit shifted in