+ 4

Any c sharp developers ever use << ? If so, why?

27th Jan 2019, 11:02 PM
Dave
Dave - avatar
3 Answers
+ 9
Imagine you have an 8x8 chessboard, and you want to store where on the board team white has placed their pawns. That would be 64 squares, each containing 1 bit of information (yes/no). So a single 64-bit integer can store everything you need, which saves a lot of space and time compared to an array. To retrieve a single square you need bitwise operators like <<, >>, |, &. This is called a "bitboard" and is common when developing AI for board games.
28th Jan 2019, 4:02 AM
Schindlabua
Schindlabua - avatar
+ 7
28th Jan 2019, 12:02 AM
ShortCode
+ 2
Yes, it’s the bitwise left shift operator. https://www.sololearn.com/learn/4087/
27th Jan 2019, 11:19 PM
Rowsej
Rowsej - avatar