what does this one do?
>int bits
initialize the variable bits as an integer
>return (bits >>> k) | (bits << (Integer.SIZE - k));
This is a bitshift operation. You can read more about those here:
https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/bitshift.html
>>340760
meant to include this:
The signed left shift operator "<<" shifts a bit pattern to the left
The signed right shift operator ">>" shifts a bit pattern to the right.
The unsigned right shift operator ">>>" shifts a zero into the leftmost position
>>340762
and this:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
"error: variable bits might not have been initialized"
But really, assuming bits and k have been defined, this takes the binary content of bits, cuts it into two pieces (one of length k at the end, and the rest at the beginning), and swaps them.
Example, if Integer.SIZE is 8, bits is 53, and k is 3:
bits:
00110101
a = bits >>> k [shift all bits over to the right by 3, moving in 0's on the left]:
00000110
b = bits << (Integer.SIZE - k) [shift all bits over to the left by 5, moving in 0's on the right]:
10100000
a | b [combine a and b, taking a 1 in a position if a or b has a 1 there, a 0 otherwise]:
10100110
So you see, since k is 3, it grabs the "101" at the end of bits and moves it up to the front. One place where this sort of operation is useful is in switching between big-endian and little-endian encodings, where basically the bytes for an integer are stored in opposite orders. For a 32-bit integer, you could perform this operation four times with k = 8 (the number of bits in a byte) to perform the conversion.
believe in yourself and the rest will follow
>>340775
Whoops I just realized that i lied here about the endian thing, you would end up with the same number doing this four times. You could come up with a way to do it by successively doing this with the n-byte tail of the number, (n-1)-byte tail, and so on, but just ignore that I said anything about endianness :) Doing this once will switch between endian types for a 16-bit int, though.
>>340756
Circular bit shift.
>>340756
java initializes bits to 0
so it is (0>>>k)| (0<<(Integer.SIZE-k))
nothing intelligible really
>>340818
A value is only initialized to 0 if it's a class variable, instance variable, or array element, none of which apply to this situation. i think the implication is that bits and k are already defined to some values regardless of what the image actually means
>>340833
then what is k or where is "int k;"
>>340835
That's what I'm saying, we're to assume that it has some reasonable value. the expression is perfectly good if you do
>>340836
bits is uninitialized
k is undefined
this is UB
if it was just
>(bits >>> k) | (bits<<(Integer.SIZE-k))
I would say bitwise rotation
>>340841
1) It's not undefined behavior, it's a compile-time error
2) I understand that the code in the image, interpreted literally, is a compile-time error. Obviously, we aren't supposed to interpret it that way. Yes, it's a bitwise rotation, as explained above
>>340873
>it's a compile-time error
I wonder if OP is just clueless or a low level troll