Original post:
<CODE>
Hi!
128>>1 gives 64, but why??
I think if 128 = 10000000
10000000>>>1 = 11000000
the restul will be 192 because the operator >> added to the left side will be the same value as the leading sign bit.
thanks in advanced
</CODE>
I don't exactly understand what you are saying but.
128 in bits is
<code>
00000000 00000000 00000000 10000000
128 >> 1 // this means that the wole bitpattern will move a step to the right. The rightmost bit falls out and disappears. Since the leftmost bit is 0 the bitpattern will add a 0 to the bitfield
that's leaving the bitfield with
00000000 00000000 00000000 01000000 = 64
</code>
Please read the
http://www.javaranch.com/campfire/StoryBits.jsp it will explain bits for you.
------------------
Preparing for the Java 2 Certification exam