Original Post
I always get compiler errors when I use << or >>, so I'm guessing it must be different in Java than in C.
Quote:
Original post by EGD Eric
I always get compiler errors when I use << or >>, so I'm guessing it must be different in Java than in C.
Quote:
Original post by DrjonesDW3d
Working with bits in java is a pain. I did some data compression stuff a while back where you were looking at everything in the bit level, it starts to become a real hassle.
Quote:
One of the major problems is that in Java a "byte" is signed. That's right, something that is almost exclusivly used for working with bits, where the value doesn't always represent something numerical is signed. That creates a lot of strange errors when shifting and working at the bit level. One thing that helped me, was that if I would cast a byte as a byte, some of those problems would go away. Yes, it doesn't make sense, but it works :)
Quote:That's why Java has a special logical right shift operator (>>>) in addition to the arithmetic one (>>).
Original post by Iftah
there is a big problem with java bit shifting,
there is no support for unsigned int (!!!)
so shifting keeps the sign of the number!
Quote:Exactly. The arithmetic one keeps the sign, so you can use it to simulate a division of signed integers (beware of rounding differences however).
Original post by EGD Eric
What's the difference between the arithmetic and logical operators? One keeps the sign, and the other one doesn't?
Quote:Doesn't most universities offer AI courses? I know my crappy local school does, without any special prerequisites.
Original post by EGD Eric
for my AI homework i wanted to compact memory as much as possible...
You had AI homework? You were (are) taking some kind of 3-year intensive computer science course? Or a game programming course?
Quote:
Original post by EGD Eric
Now I realise what I was doing wrong, I was trying something like this:
val << 8;
that doesn't work, you have to go: val = val << 8;
int x = 5;x+1;Quote:
Original post by Fred304 Quote:
Original post by EGD Eric
Now I realise what I was doing wrong, I was trying something like this:
val << 8;
that doesn't work, you have to go: val = val << 8;
Mind that this is nothing special about the >> operator. For example:int x = 5;x+1;
does not work either, you have to use x = x+1;
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more