Answers.Body: <p>0x88 is just the name of the system.  The actual length of the board array is 128.  </p>
  
  <p>The name comes from the fact that a bitwise AND can be performed the index of a square (range is 0 to 127) and 0x88.  If the result is non-zero, then the square is not on the board.  This happens because 0x88 is <code>10001000</code> in binary and every square on the board will have the form <code>0xxx0xxx</code>.</p>
  
  <p>Another benefit of the system is that all of the legal squares can be trivially constructed in octal notation.  For example, <code>d4</code> is <code>0x33</code> assuming that 0x00 is the lower left of the board (both d and 4 are the 4th square from the edge, so 3 in a zero-indexed array).  </p>
  
  <p>See <a href="https://chessprogramming.wikispaces.com/0x88">https://chessprogramming.wikispaces.com/0x88</a> for more information about this system.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-23T22:03:06.737Z
Answers.Text: Hi Andrew and thanks for your swift reply. I'm still not sure about this bitwise op and why the system is called 0x88. Hopefully if I read more about it I will come to understand it more. I looked at your link but I do not understand this yet " 0x88 is C-syntax and the hexadecimal value of a mask of bits need to be zero for valid square coordinates (136 decimal, 210 octal, 10001000B)."  I hope that given time I will get to understand this chessboard representation properly! Best wishes :-)
Answers.UserDisplayName: rpd
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-23T23:24:08.890Z
Answers.Text: @rpd As an example, consider finding all of the moves to the right for a rook on `g1`. That square is 0x06. To get to the next square, we add 1: 0x07. Then we test to see if it's on the board (0x88 & 0x07 => 0). Since that is zero, it's on the board (the `h1` square). Repeat: 0x08 is the next square (`i1`) and the bitmask is as follows: 0x08 & 0x88 => 0x08.  Since that is non-zero, the square is off the board and the move `Rg1-i1` is illegal. These bitwise operations were much faster than memory lookup in early programs which is why this system is so popular.
Answers.UserDisplayName: Andrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-24T17:18:20.167Z
Answers.Text: Andrew,many thanks for your further helpful explanation. I am a novice C programmer still & as I do not yet understand using 0x88 as a mask(?) or ANDing it with the next square as a test for on board square. I will be looking at this int ime and I'm sure I will understand it properly. I have been looking at chess board reps and I will be sticking with a 1D or 2D 64 square array (unless I use 12x12 array or 10x12 array to help off board square detection). Later I may consider 0x88 system but I need to learn it properly first! Again many thanks for your clear explanation of 0x88..best wishes
Answers.UserDisplayName: rpd
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-23T21:51:46.110Z
Answers.LastActivityDate: 2013-12-23T21:51:46.110Z
Answers.UserDisplayName: Andrew
Body: <p>I am starting to look at chessboard representation with the 0x88 hex array board rep, but I'm getting confused! Please help me understand it properly!</p>
  
  <p>The 0x88 chess board representations I have seen as examples around on net resources say it can be thought of as representing a 16x8 2D array (size 128 and so is used as 2 boards side by side to check off board moves etc). </p>
  
  <p>However, afaik, hex value 0x88 is equivalent to 136 in decimal (10001000 in binary) so why is the array size not size 136 (136 bytes)?
  I must be overlooking something simple with this. I apologise for this and will no doubt feel very foolish when I find what mistaken thinking my brain is stuck with over this!</p>
  
  <p>I am grateful for any helpful replies,many thanks</p>
  
Tags: <chessboards>
Title: Why is a 0x88 chessboard array of size 128 bytes when 0x88 is decimal 136?
ThreadText: # Why is a 0x88 chessboard array of size 128 bytes when 0x88 is decimal 136?
  
  (Asked by: username_0 on 2013-12-23)
  
  I am starting to look at chessboard representation with the 0x88 hex array board rep, but I'm getting confused! Please help me understand it properly!
  
  The 0x88 chess board representations I have seen as examples around on net resources say it can be thought of as representing a 16x8 2D array (size 128 and so is used as 2 boards side by side to check off board moves etc).
  
  However, afaik, hex value 0x88 is equivalent to 136 in decimal (10001000 in binary) so why is the array size not size 136 (136 bytes)?
  I must be overlooking something simple with this. I apologise for this and will no doubt feel very foolish when I find what mistaken thinking my brain is stuck with over this!
  
  I am grateful for any helpful replies,many thanks
  
  **Tags:** chessboards
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2013-12-23. Score: 7 | Accepted answer
  
  0x88 is just the name of the system. The actual length of the board array is 128.
  
  The name comes from the fact that a bitwise AND can be performed the index of a square (range is 0 to 127) and 0x88. If the result is non-zero, then the square is not on the board. This happens because 0x88 is `10001000` in binary and every square on the board will have the form `0xxx0xxx`.
  
  Another benefit of the system is that all of the legal squares can be trivially constructed in octal notation. For example, `d4` is `0x33` assuming that 0x00 is the lower left of the board (both d and 4 are the 4th square from the edge, so 3 in a zero-indexed array).
  
  See <https://chessprogramming.wikispaces.com/0x88> for more information about this system.
  
  > **Comments:**
  > **username_0**: Hi username_1 and thanks for your swift reply. I'm still not sure about this bitwise op and why the system is called 0x88. Hopefully if I read more about it I will come to understand it more. I looked at your link but I do not understand this yet " 0x88 is C-syntax and the hexadecimal value of a mask of bits need to be zero for valid square coordinates (136 decimal, 210 octal, 10001000B)."  I hope that given time I will get to understand this chessboard representation properly! Best wishes :-)  
  > **username_1**: @username_0 As an example, consider finding all of the moves to the right for a rook on `g1`. That square is 0x06. To get to the next square, we add 1: 0x07. Then we test to see if it's on the board (0x88 & 0x07 => 0). Since that is zero, it's on the board (the `h1` square). Repeat: 0x08 is the next square (`i1`) and the bitmask is as follows: 0x08 & 0x88 => 0x08.  Since that is non-zero, the square is off the board and the move `Rg1-i1` is illegal. These bitwise operations were much faster than memory lookup in early programs which is why this system is so popular.  
  > **username_0**: username_1,many thanks for your further helpful explanation. I am a novice C programmer still & as I do not yet understand using 0x88 as a mask(?) or ANDing it with the next square as a test for on board square. I will be looking at this int ime and I'm sure I will understand it properly. I have been looking at chess board reps and I will be sticking with a 1D or 2D 64 square array (unless I use 12x12 array or 10x12 array to help off board square detection). Later I may consider 0x88 system but I need to learn it properly first! Again many thanks for your clear explanation of 0x88..best wishes  
  
  ---
  
  