• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Galaxy has no >>> *rage*

Status
Not open for further replies.
I am forced to do this

Code:
int logicalRightShiftInt(int x, int n) {
    return (x & 0x7fffffff) >> n | -((x & 1 << 31) >> n);
}

And I love lack of typecast

Code:
static const byte H_1 = 1;
static const byte H_7F = 0x7f;
static const byte H_80 = 0x80;
byte logicalRightShiftByte(byte x, byte n) {
    return (x & H_7F) >> n | (~((x & H_80) >> n) + H_1);
}


Respond to this post and help get Blizzard to add >>> operator

http://us.battle.net/sc2/en/forum/topic/9423382586

edit
nvm, >>> is a Java thing, not a C thing, but there is still a srl operator D;, and Galaxy doesn't support typecasting and only has signed, so they should really add a >>> cuz it's very annoying to do it otherwise.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Just so people who are not Java gurus know.

>> Is bit wise right shift. It will fill with 0 bits if the number is positive and 1 bits if the number is negative.
>>> Is unsigned bit wise right shift. It will always fill with 0 bits.

The reason >>> is so useful is that the resulting number is more friendly for use with bit wise or (|) since it means that the substituted bits will come from whatever you or the integer with. That is obviously just a simple reason, there are many more.

In JAVA all bitwise operators were either int or long, meaning that using them on a smaller value (short, byte or char) resulted in it being converted to an int (padded with 0 for positive and 1 for negative) so an extra bit wise and step was required to make sure unsigned mathematics computed correctly using the signed types. This should have been optimized out during the virtual machine compilation process so performance wise have no impact.
 
Status
Not open for further replies.
Top