Unreal >>> operator vs. Java >>> operator

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

jimboh

Salty Sea Dog
Jan 20, 2004
140
0
0
Roaming the high seas...
Okay, so I'm trying to port over a piece of code from Java. Unfortunately, for some reason, Java's >>> shift operator is different from unreal's >>> operator. An example is when you try to do
Code:
24 >>> 32
In the original Java version, it returns 0, but in Unreal, it returns 24. I know that Java and Unreal both use signed ints, so it should theoretically return the same. The only difference that I can think of is that Java uses the big endian format, while Unreal possibly uses the little endian format (since it is mostly compiled on Intel x86 processors). So anyone know the problem, and hopefully a solution? :(

Thanks in advance! :)
 

jimboh

Salty Sea Dog
Jan 20, 2004
140
0
0
Roaming the high seas...
well, after more investigation into this matter, it seems that n # 32 where n is an integer and # is the operations: <<, >>, >>> will usually always return n.

Kinds seems that the people at Epic were a bit lazy when implementing the bitwise shift operators...
 

elmuerte

Master of Science
Jan 25, 2000
1,936
0
36
42
the Netherlands
elmuerte.com
endianess only has effect on byte level access of larger integers, it has nothing to do with with bit shifting operators.

as for the >> operator, it's a direct mapping to the C++ >> operator
the >>> operator first converts the first parameter to an unsigned int then applies the >> operator.

Apperently, according to your info, bit shifting wraps the bits, which would be odd.
 
Last edited:

jimboh

Salty Sea Dog
Jan 20, 2004
140
0
0
Roaming the high seas...
Yeah, I got confused at first, then I was browsing through UrealWiki's Operators page, and found that
For the shift operators, only the 5 least significant bits of the second operand are used.
so I guess it would truncate the 0b100000 (or 32) into 0b00000 (or 0) so in effect:
where n = integer,
x = operators <<, >>, >>>,
(n x 32 == n x 0) would be true.