0

Explain << and >>

I know binary and I know these have to do something with binary, but I don‘t actually know how they work or where someone would use them.

7th Feb 2018, 5:37 AM
EnderJanYT
EnderJanYT - avatar
3 Respuestas
+ 2
They are bitshifters, they "move" the bits up or down so that 101 would become 1010 or 10 respectively. It can be used as flags for various properties: int flag = 0; if hasProperty1 flag += 1 flag << 1 if has property 2 flag += 1 flag << 1 etc. in the binary representation this would be a series of 1s and 0s which we can use & (bitwise AND) to identify these flags. This is used in the Java Reflection package, all of the modifiers for a variable or method declaration have a number flag and you can get the method and do stuff like method.isFinal() or method.isPublic() which uses these << In a maths setting working with powers of 2 they can be quite efficient I think
7th Feb 2018, 6:54 AM
Dan Walker
Dan Walker - avatar
+ 2
bitwise operators. very seldom used.
7th Feb 2018, 6:43 AM
Tim Millar
Tim Millar - avatar
+ 1
hi, you can use it to create a "chenillard". Sorry i don't know his name in english. if you want display 3 news one by one, give a value 1, 2, 4 and use << to select news and loop
7th Feb 2018, 6:46 AM
MBZH31
MBZH31 - avatar