[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

what does this one do?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 14
Thread images: 1

File: wdtd.png (7KB, 441x52px) Image search: [Google]
wdtd.png
7KB, 441x52px
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
Thread posts: 14
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.