Bit masking

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Bit masking

Postby matrix101 » 22 Feb 2015, 19:28

Hello,

I think I understand what bitmasking is , setting zero the bits we do not want in the result.

For example:

Code: Select all

RRRR RGGG GGGB BBBB                                           // Color values stored in a 16-bit value
const unsigned short redMask   = 0xF800;
unsigned short lightGray = 0x7BEF;

unsigned short redComponent   = (lightGray & redMask) >> 11;



would mean

0XF800 = 1111100000000000
0x7BEF = 0111101111101111

(lightGray & redMask) = 01111000000000000

(lightGray & redMask ) >>11 = 0000000000001111


However I don`t understand these bit patterns https://chessprogramming.wikispaces.com/Encoding+Moves

Why anding with 0x3f? How do I choose TARGET SQUARE (Move) = (Some bit pattern) >> 8
matrix101
 
Posts: 53
Joined: 02 Feb 2014, 12:46

Re: Bit masking

Postby H.G.Muller » 22 Feb 2015, 20:03

0x3f = 63 is 6 consecutive 1 bits. This can be used to mask a square number (0-63) out of a move encoding that, say, uses the lowest 6 bits (b0-b5) to store the to-square, the next 6 (b6-b11) as from-square, and b12-b16 to indicate the move has side effects (like e.p., castling or promotion). To obtain the from-square number you would first have to shift 6 bits, and then mask (move >> 6 & 0x3f).
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL


Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 22 guests