Arithmetic right shifts and negative values with One's/Two's complement
  1. I'm kind of unclear what the purpose of arithmetic right shifts are. From some testing, it looks like for both One's complement and Two's complement negative values, an arithmetic right shift by k is equivalent to dividing by 2^k (and rounding towards negative infinity). Whereas a logical right shift will give you some useless (positive) value. Is that true?

  2. The main purpose of Two's complement is to not have duplicate representations for zero (ie 0 and -0 are the same). Is that correct? If not, why does Two's complement exist?

πŸ‘︎ 3
πŸ’¬︎
πŸ“…︎ Sep 04 2021
🚨︎ report
How do the bit shift operators work on arithmetic combinators?

Recently, I've begun learning the circuit network, but I am unable to find any resources covering specifically the bit shift operators. Can any geniuses on reddit give me the rundown? Thx!

πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/xXbenjyboyXx
πŸ“…︎ Feb 01 2021
🚨︎ report
BUG? You can recruit prisoners with "arithmetic progression" by holding SHIFT

Not sure if it's already well-known but I have been exploiting this "bug" for a while.

When you keep prisoners in your party, in time they will gradually become recruitable. There will be an icon that indicates how many prisoners of this unit you can recruit. For example, if you have 10 imperial trained infantryman and the icon says 4, technically it means you can left click icon 4 times and recruit 4 units with 6 prisoners left. However, if you do it by holding SHIFT then left click it 4 times, you can actually recruit 4 + 3 + 2 + 1 = 10 units. You can recruit all of them! Each SHIFT click gives you "x" unit of the prisoners (where x is the face value of the icon) while it only reduces its number by 1 even with SHIFT, so you can SHIFT click it 4 times.

SHIFT click 2 times can recruit 3 (2 + 1), while normal click 2 times only recruit 2 (1 + 1) with 1 prison left

On the other hand, you can also keep accumulating the recruitable number and only use one single SHIFT click and then wait for the number to come back (the recruitable number is of course capped at the amount of the prisoners with the same type in your party).

I usually keep like 4~5 prisoners of the units I want in my party and wait for the icon to accumulate. After that I go to my settlement and pull more prisoners with the same type then use this bug to recruit many of them. This is especially useful when you want to recruit a plenty of high-tier prisoners.

Remember this trick only works when you are holding SHIFT and left click. It works normally (+1, +1, ...) if you just left click without SHIFT.

In conclusion, don't recruit prisoners as soon as they become available. Keep these recruitable in your party and accumulate the recruitable number. Then use SHIFT click trick to recruit a plenty of them!

πŸ‘︎ 22
πŸ’¬︎
πŸ‘€︎ u/Tay2510
πŸ“…︎ Jun 20 2020
🚨︎ report
[C#] How was the arithmetic shift performed with the right shift operator?

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators#code-try-1

"If the left-hand operand is of type int or long, the right-shift operator performs an arithmetic shift: the value of the most significant bit (the sign bit) of the left-hand operand is propagated to the high-order empty bit positions. That is, the high-order empty bit positions are set to zero if the left-hand operand is non-negative and set to one if it's negative."

 int a = int.MinValue;
 Console.WriteLine($"Before: {Convert.ToString(a, toBase: 2)}");

int b = a >> 3;
Console.WriteLine($"After:  {Convert.ToString(b, toBase: 2)}");
// Output:
// Before: 10000000000000000000000000000000
// After:   11110000000000000000000000000000

===========

Not sure if I understand the thing. Which ones are high-order empty bit positions? 1000 - the last three 0s? And they were replaced by 1 which is the value of MSB? But it also say they will be set to zero if the left hand operand is non negative

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/vberkova
πŸ“…︎ May 17 2020
🚨︎ report
Bitcoin SV gets a black eye from Greg as they mess up the implementation of basic arithmetic left and right shift. twitter.com/el33th4xor/st…
πŸ‘︎ 14
πŸ’¬︎
πŸ‘€︎ u/throwawayo12345
πŸ“…︎ Aug 31 2018
🚨︎ report
voyage in cov*d reality shifts [electro-acoustic ambient-ish, raytraced 4d julia fractal arithmetic on 4d worley noise, parameters and camera in response to semantic musical content] vimeo.com/lazerbeams/why
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/LazerbeamsTONITE
πŸ“…︎ May 05 2020
🚨︎ report
[College-Level Computer Science/Progamming] - Turn Logical Right Shift Into Arithmetic Right Shift using only low-level programming statements - tips/assistance?

(Sorry for repost, but my original post's title didn't specify the level of schooling, just "Computer Science". I removed the old one - sorry, honest mistake!)

I've been attempting the following problem for a while, but unfortunately made little progress:

Fill in the code for the following C function: Function sra performs an arithmetic right shift using a logical right shift (given by value xsrl), followed by other operations not including right shifts or division. You may use the computation 8 * sizeof(int) to determine w, the number of bits in data type int. The shift amount k can range from 0 to w - 1.

int sra(int x, int k) {

/* Perform shift logically */

int xsrl = (unsigned) x >> k;

}

The code is meant to work on systems of variable size, which is why I can't just assume 4-byte integers. I also can't use if statements, loops, comparators except for == and !=, or other higher-level programming constructs. The only library stuff I can access is INT_MAX and INT_MIN, which were useful for some earlier problems in the section but I don't think I need them here.

So far, here's what I have:

int sra(int x, int k) {

`/*Perform shift logically */`

`int xsrl = (unsigned) x >> k;`

`/*Currently the leading digits are definitely zeroes. What needs to be figured out, is whether the leading digit was formerly a one or a zero, and then change the digits accordingly.`

 `We know how many bits to the right it was shifted. So make a copy, called copysrl. */`

int copysrl = xsrl;

 `Shift copysrl LEFT k times.`

copysrl = copysrl << k;

 `Create an integer of value 1 called mostSignificantBit.`

 `Left shift mostSignificantBit w - 1 times, so you get 0x8000...0 as the result bit pattern.`

int mostSignificantBit = 1 << (sizeof(int) * 8 - 1);

 `mostSignificantBit = copysrl & mostSignificantBit. This will turn mostSignificantBit into either 0x8000...0 or 0x000...0, depending on whether the original int x had a 1 as its leading bit.`

mostSignificantBit = mostSignificantBit & copysrl;

}

At this point I hit something of a snag, and I suspect I've actually been going about the problem a bit incorrectly based on it. The one thing I'm sure of is that I need to somehow take xsrl and extract the information about whether its most significant bit was a 1 or a 0, since that's the key to getting an arithmetic right shift. My code does this currently, and th

... keep reading on reddit ➑

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/Kesseleth
πŸ“…︎ May 14 2019
🚨︎ report
My arithmetic chip, registers, B2U decoders, and SIPO shift registers. youtube.com/watch?v=r9Tal…
πŸ‘︎ 2
πŸ’¬︎
πŸ“…︎ Jul 20 2019
🚨︎ report
BSV subsidizes new logical shift operations at great expense to Satoshi's vision for arithmetic shifts.

Acknowledging the replacement of Bitcoin's original arithmetic OP_LSHIFT and OP_RSHIFT opcodes with new truncated logical operations, BSV developer u/danconnolly had this to say:

> For the LSHIFT and RSHIFT opcodes, these opcodes were updated to be bitwise operators which means that they operate on byte sequences, not numeric values. This means that they do not have special treatment for the sign bit and they don’t overflow or underflow. They operate on all sizes of byte sequences, from zero-length up to the maximum element size (520 bytes).

> Previously, the LSHIFT and RSHIFT operated on numeric values. This same functionality can be achieved through the use of script, possibly including the bitwise LSHIFT and RSHIFT opcodes.

https://www.reddit.com/r/btc/comments/9ce492/bsvs_new_op_lshift_and_op_rshift_are_not/e5b9vpe

He goes on to provide an example of Script that could be used to simulate Satoshi's intended functionality. This plainly requires many times more steps to perform what was meant to be a simple operation, inflating the size and complexity of scripts making use of Satoshi's original design, not to mention the cost to perform these basic operations.

Just as arithmetic shifts can be performed using complex chunks of Script in place of the designated opcode, logical shifts can be performed using other basic operations. In fact, logical shifts are much easier to simulate as they are nothing more than multiplication or division by a power of 2. Furthermore, BSV eliminated the OP_2MUL and OP_2DIV opcodes which are identical to the special case of logically shifting left or right by one, respectively. If logical shifts are of such vital functionality that they require subsidized and dedicated opcodes, there is no reason the deprecated opcodes could not have been repurposed as logical shift operators while retaining the arithmetic counterparts.

Not only does BSV alter Satoshi's original protocol by introducing these novel operations, it does so as a centrally planned economic change. In the guise of "achiev[ing] balance between minimizing the number of opcodes and providing the functionality" BSV diverges from Satoshi's vision as implemented in his original client, applying a disproportionate penality on performing the intended functionality while BSV's preferred operations benefit from a subsidy.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/cryptocached
πŸ“…︎ Oct 18 2018
🚨︎ report
The mother of all paradigm shifts: Interval Arithmetics research.sun.com/minds/20…
πŸ‘︎ 206
πŸ’¬︎
πŸ‘€︎ u/soegaard
πŸ“…︎ Feb 14 2006
🚨︎ report
Where is arithmetic (signed) right-shift?

I've been searching through Rust docs (and source code), and it looks like Rust does not provide arithmetic the (signed) right-shift operator. Is this true?

If it is true, then why? I'm working on porting some high-performance code to Rust, and it depends heavily on ASR.

πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/0xdeadf001
πŸ“…︎ Nov 08 2014
🚨︎ report
Basic arithmetic in young chidren 7-9 years old relies on counting but in teenagers 14-17 shifts to a memory-based system as hippocampus becomes involved med.stanford.edu/news/all…
πŸ‘︎ 26
πŸ’¬︎
πŸ‘€︎ u/ignobel9
πŸ“…︎ Sep 04 2014
🚨︎ report
Has the parliamentary arithmetic shifted decisively in favour of a referendum? ukandeu.ac.uk/crunching-t…
πŸ‘︎ 15
πŸ’¬︎
πŸ“…︎ Oct 12 2019
🚨︎ report
[C Bit Operators] A function that rotates bits to the right fails if the number of rotations = 0. (Right arithmetic shifting by a negative number? Aww heck.)

EDIT: SOLVED! Solution at the bottom.

Hey all! Sorry to keep spamming you guys. Think this is my third post here this week. I'd be in the tutoring room, but sadly it's closed on Saturdays.

The goal of this part of the assignment is to make a function that rotates bits to the right, and then place them on the left if they hit the LSB. If that makes sense.

My code actually works in all situations, except where n (the number of shifts or rotations) is equal to zero.

As stated before, this is a homework assignment, and we're limited to a few operators (! ~ & ^ | + << >>).

We cannot use LOOPS, CONDITIONALS, FUNCTION CALLS, RECURSION, etc. Just the ops.

Here are the instructions:

/* 
 * rotateRight - Rotate x to the right by n
 *   Can assume that 0 &lt;= n &lt;= 31
 *   Examples: rotateRight(0x87654321,4) = 0x76543218
 *   Legal ops: ! ~ &amp; ^ | + &lt;&lt; &gt;&gt;
 *   Max ops: 25
 *   Rating: 3 
 */

NOTE: Shifts are arithmetic and the ints are signed 32-bit ints.

And here is my code:

int rotateRight(int x, int n) {
    //Need to create a mask n long of all 1's, to store the first n numbers.
    //(1 &lt;&lt; n) - 1 does so. However, can't use -1. However, (x - 1) = ~(~x + 1)
    int mask = ~(~(1 &lt;&lt; n) + 1);
    int right = x &amp; mask; //Rightmost n bits now stored. 

    //Shift x the appropriate value
    x = (x &gt;&gt; n); 

    //Need to clear out the first n bits so the rightmost bits can take their place.
    //int a = (1 &lt;&lt; 31) &gt;&gt; (n - 1)
    int a = ~((1 &lt;&lt; 31) &gt;&gt; ~(~n + 1));

    x = (x &amp; a);

    //Now just need to put the right bits in the leftmost spot. 
    //right = right &lt;&lt; (wordsize - n);
    //right = right &lt;&lt; (wordsize + (~n + 1));
    right = right &lt;&lt; (32 + (~n + 1));

    return(right | x);
}

Despite being a bit ugly, it actually works in all cases except where n (the number of shifts or rotations) equals to zero.

Let's look at an example where it works: (For the sake of saving time, I'll do 8-bit words instead of 32-bit works)

http://pastebin.com/68aUWrbk (Pastebin because it's hecking long, ignore the 31 on line 24, that should be a 7, or word size - 1)

See how it works?

Now let's try the same thing, but shifted by ZERO instead.

http://pastebin.com/JbmcD4Uk

See the issue?

It's junk if I try to rotate by zero.

Does anyone know a way of fixing this issue without compeltely re-

... keep reading on reddit ➑

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/Night_Thastus
πŸ“…︎ Oct 01 2016
🚨︎ report
Paul Krugman - I observed that Republicans seemed to have lost interest in the war on terror and shifted focus to the war on arithmetic. Now the G.O.P. has moved on to an even bigger project: the war on logic. nytimes.com/2011/01/17/op…
πŸ‘︎ 121
πŸ’¬︎
πŸ‘€︎ u/BlackRyder
πŸ“…︎ Jan 17 2011
🚨︎ report
Why is signed right shift implementation defined?

What would be most useful

(unsigned)x&gt;&gt;10 Guarinteed to be logical

(signed)x&gt;&gt;10 Guarinteed to be arithmetic

But what we have is

(unsigned)x&gt;&gt;10 Guarinteed to be logical

(signed)x&gt;&gt;10 Can be logical or arithmetic implementation defined

Why?

Although it can easily be tested to be arithmetic by (((-1)&gt;&gt;1)==-1) why the extra complications?

Also what is the fastest way to perform a guaranteed arithmetic right shift in C?

πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/BlockOfDiamond
πŸ“…︎ Dec 06 2021
🚨︎ report
[General] How much does arithmetic shifting really help in a process?

We discussed today how shifting arithmetic can help considerably, but no real metric were used. It seems like it can be a considerable hangup down the road if you ever have to use a number that isn't 2^x

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/rohanivey
πŸ“…︎ Feb 05 2014
🚨︎ report
MCC19 Grid Runner analysis, prediction, and why the team need more time

We all know how only 3 teams finished Grid runners MCC 19, so what did the teams do? What could Noxcrew have improved? Would the teams have benefited from 3 extra minutes? and where would they have placed?

I’ve done an analysis on each of the teams, after this there is the Slime Push room which only 4 teams finished. I then predict when the teams would have finished the room and finally had the teams been given 15 minutes instead of 12, would they have finished?

Room 1: Shave Santa

Red: GNF's pov, 0:30, 2nd

Krinios and Punz went up top while Eret and George were down below. This was a good spread as they could cover all corners of the santa.

Ginger: Grian's pov, 0:29, 1st

They immediately went low first, Pete being the movement god he is, was up there right away with Grian struggling for a way up and Jimmy and Gem on the lower.

Yellow: Captain's pov, 0:33, 3rd

This team started a lot like ginger, three on the bottom with Quig at the top. Because Quig was up the top on his own his team had to wait while he finished his area. Even with this delay, they had a good time.

Mint: Joel's pov, 0:51, 8th

In this team no one went high right away. This was due to Martyn trying to make the jump up there, failing and deciding they weren't meant to get up there. After searching for a way up, False got up and was able to do the rest.

Emerald: Ranboo's pov, 0:56, 9th

Immediately everyone goes bottom, however Dream says that someone should go up, from here they split into two groups, Ranboo and Charlie taking lower while Dream and Tubbo try to find a way up. The communication was on point.

Teal: Phil's pov, 0:34, 4th

Phil and Sneg went down while Sapnap and Tommy went up. Tommy and Sapnap were in the same area at the top, causing them to lose maximum efficiency on this one. But this issue was small.

Cerulean: Fruit's pov, 0:34, 5th

3 players going lower and one on top, Sam later joining.

Sapphire: Vixella's pov, 0:49, 7th

Everyone started lower but someone realised that someone should

... keep reading on reddit ➑

πŸ‘︎ 233
πŸ’¬︎
πŸ‘€︎ u/Idiotsandwich55
πŸ“…︎ Dec 14 2021
🚨︎ report
Blind Girl Here. Give Me Your Best Blind Jokes!

Do your worst!

πŸ‘︎ 5k
πŸ’¬︎
πŸ‘€︎ u/Leckzsluthor
πŸ“…︎ Jan 02 2022
🚨︎ report
What starts with a W and ends with a T

It really does, I swear!

πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/PsychedeIic_Sheep
πŸ“…︎ Jan 13 2022
🚨︎ report
Dropped my best ever dad joke & no one was around to hear it

For context I'm a Refuse Driver (Garbage man) & today I was on food waste. After I'd tipped I was checking the wagon for any defects when I spotted a lone pea balanced on the lifts.

I said "hey look, an escaPEA"

No one near me but it didn't half make me laugh for a good hour or so!

Edit: I can't believe how much this has blown up. Thank you everyone I've had a blast reading through the replies πŸ˜‚

πŸ‘︎ 19k
πŸ’¬︎
πŸ‘€︎ u/Vegetable-Acadia
πŸ“…︎ Jan 11 2022
🚨︎ report
This subreddit is 10 years old now.

I'm surprised it hasn't decade.

πŸ‘︎ 10k
πŸ’¬︎
πŸ‘€︎ u/frexyincdude
πŸ“…︎ Jan 14 2022
🚨︎ report
What is a a bisexual person doing when they’re not dating anybody?

They’re on standbi

πŸ‘︎ 11k
πŸ’¬︎
πŸ‘€︎ u/Toby-the-Cactus
πŸ“…︎ Jan 12 2022
🚨︎ report
What do you call quesadillas you eat in the morning?

Buenosdillas

πŸ‘︎ 12k
πŸ’¬︎
πŸ‘€︎ u/FarronKeepSucks
πŸ“…︎ Jan 14 2022
🚨︎ report
Geddit? No? Only me?
πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/shampy311
πŸ“…︎ Dec 28 2021
🚨︎ report
I wanna hear your best airplane puns.

Pilot on me!!

πŸ‘︎ 3k
πŸ’¬︎
πŸ‘€︎ u/Paulie_Felice
πŸ“…︎ Jan 07 2022
🚨︎ report
E or ß?
πŸ‘︎ 9k
πŸ’¬︎
πŸ‘€︎ u/Amazekam
πŸ“…︎ Jan 03 2022
🚨︎ report
No spoilers
πŸ‘︎ 9k
πŸ’¬︎
πŸ‘€︎ u/Onfour
πŸ“…︎ Jan 06 2022
🚨︎ report
i Karenough to
πŸ‘︎ 4k
πŸ’¬︎
πŸ‘€︎ u/Amazekam
πŸ“…︎ Jan 14 2022
🚨︎ report
Covid problems
πŸ‘︎ 7k
πŸ’¬︎
πŸ‘€︎ u/theincrediblebou
πŸ“…︎ Jan 12 2022
🚨︎ report
Sumerian Nights 🌠

A very merry unbirthday cake day to me! πŸŽ‰πŸ€© Hi there, my awesome friends! Feeling ready for the update? I can’t wait, getting through this week with my sanity intact has been a heroic feat, ngl! I’m back with my tradition of posting a β€œsmall” something right before RC drops the new episodes... this time I actually had decided to anticipate a little (I wanted to post it on Wednesday… good job me!), for celebrating my cake day (thanks to the dear friends who noticed in my stead #always-with-my-head-in-the-clouds)... you can see how that went! πŸ˜…πŸ˜¬ Oh well... I'm finally here! And to be completely honest, the real reason I wrote this post is that I just needed an excuse to bask once again in the perfection of this poster:

Have you ever seen something more beautiful?

I'n not ashamed to admit that I kept ging back to the original post just to look at its awesomeness. After I got accustomed to the divine beauty of this art, I noticed four constellations in the background, standing out from the homogeneous starry sky. The curiosity got the best of me, and I started looking into Mesopotamian star charts, delving into a topic I was familiar with but I never really β€œdissected”. I got reminded/found out a great deal of interesting things, and I especially noticed that astronomy is the perfect shortcut to deal with the Sumerian civilisation as a whole, in order to get acquainted with the story setting before it even started! Of course, the infos about it will be those somewhat relevant to the matters at hand, but feel free to ask anything you are curious about these ancient and sophisticated civilisations, who lived in Mesopotamia, the β€œLand between Two Rivers” (since it seems that some are not very familiar with them… one more reason to talk about it, before TFT airs! Ask in the comments whatever you are curious about, if you want!)

Let’s get into it! Bear with me, for a little while: after a swift introduction, we will move right away to our Sumerian friends! In modern astronomy, the heavenly vault is divided into 88 parts, each one of them corresponding to a constellation. Now, in purely scientific terms, constellations do not mean anything: they are just imaginary lines drawn between stars, or rather, the projection of stars on the heavens from our earthly point of view, created in the past for a plethora of reasons, from th

... keep reading on reddit ➑

πŸ‘︎ 56
πŸ’¬︎
πŸ“…︎ Nov 28 2021
🚨︎ report
These aren't dad jokes...

Dad jokes are supposed to be jokes you can tell a kid and they will understand it and find it funny.

This sub is mostly just NSFW puns now.

If it needs a NSFW tag it's not a dad joke. There should just be a NSFW puns subreddit for that.

Edit* I'm not replying any longer and turning off notifications but to all those that say "no one cares", there sure are a lot of you arguing about it. Maybe I'm wrong but you people don't need to be rude about it. If you really don't care, don't comment.

πŸ‘︎ 12k
πŸ’¬︎
πŸ‘€︎ u/Lance986
πŸ“…︎ Dec 15 2021
🚨︎ report
I had a vasectomy because I didn’t want any kids.

When I got home, they were still there.

πŸ‘︎ 10k
πŸ’¬︎
πŸ‘€︎ u/demotrek
πŸ“…︎ Jan 13 2022
🚨︎ report
Spi__
πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/Fast_Echidna_8520
πŸ“…︎ Jan 11 2022
🚨︎ report
I dislike karma whores who make posts that imply it's their cake day, simply for upvotes.

I won't be doing that today!

πŸ‘︎ 15k
πŸ’¬︎
πŸ‘€︎ u/djcarves
πŸ“…︎ Dec 27 2021
🚨︎ report
The Ancient Romans II
πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/mordrathe
πŸ“…︎ Dec 29 2021
🚨︎ report
How do you stop Canadian bacon from curling in your frying pan?

You take away their little brooms

πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/Majorpain2006
πŸ“…︎ Jan 09 2022
🚨︎ report
What did 0 say to 8 ?

What did 0 say to 8 ?

" Nice Belt "

So What did 3 say to 8 ?

" Hey, you two stop making out "

πŸ‘︎ 9k
πŸ’¬︎
πŸ‘€︎ u/designjeevan
πŸ“…︎ Jan 03 2022
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.