[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I convert the Java bitwise shift operator '>>>' to C Sharp?

Posted on 2008-06-11
8
Medium Priority
?
444 Views
Last Modified: 2013-12-17
Java has shift operators >>, << and  >>> but C-sharp only has >> and <<.
How would I translate >>> in Java to C-sharp?
0
Comment
Question by:ludy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 2

Expert Comment

by:jml948
ID: 21766553
The details behind the ">>>" operator seem to be explained as follows:

n >>> s

if n is positive then its the same as n >> s

but if n is negative there are two cases:
   if n is an int and negative then:
       n >>> s = (n>>s)+(2<<~s)
   if n is a long and negative then:
       n >>> s = (n>>s)+(2L<<~s)

So I would try the following:

    static int UnsignedRightShift(int n, int s) //n is an integer
    {
          if(n > 0){
               return n>>s;
          }else{
               return (n>>s)+(2<<~s);
          }
    }
    static long UnsignedRightShift(long n, int s)  //Overloaded function where n is a long
    {
          if(n > 0){
               return n>>s;
          }else{
               return (n>>s)+(((long)2)<<~s);
          }
    }

0
 

Author Comment

by:ludy
ID: 21766972
ok i will try this first...
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21775577
you can achieve similar efect by casting the variable to unsigned and using the >> operator.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21775621
by example:
unsigned int result = ((unsigned int)yourVariable) >> yourShift;

0
 

Author Comment

by:ludy
ID: 21776047
how about n >>>= 1? it's also used in java.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 21776063
it is similar to:

n = ((unsigned int)n) >> 1;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question