C# equivlanet of Java's unsigned right shift operator (>>>)

A

almurph

Hi Folks,

Quick one. I am doing some reverse engineering of some Java and
have come accross the following Java code:

/* Java */
int c = (a + b) >>> 1;

I want to reverse engineer it. Here is my equivalent. Comments/
suggestions much appreciated:

/* C# reverse enginner attempt */

int c = (int)(((uint)(a + b)) >> 1)


Once again comments/suggestions/improvements are appreciated...
Colm
 
A

Arne Vajhøj

Quick one. I am doing some reverse engineering of some Java and
have come accross the following Java code:

/* Java */
int c = (a + b)>>> 1;

I want to reverse engineer it. Here is my equivalent. Comments/
suggestions much appreciated:

/* C# reverse enginner attempt */

int c = (int)(((uint)(a + b))>> 1)


Once again comments/suggestions/improvements are appreciated...

It is one way.

You could also use:

int c = (a + b) >> 1;
if(c < 0) c += 0x80000000;

or:

int c = 0x7FFFFFFF & ((a + b) >> 1);

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top