https://www.chessprogramming.org/index.php?title=Byte&feed=atom&action=historyByte - Revision history2024-03-29T00:14:32ZRevision history for this page on the wikiMediaWiki 1.30.1https://www.chessprogramming.org/index.php?title=Byte&diff=2744&oldid=prevGerdIsenberg: Created page with "'''Home * Programming * Data * Byte''' A '''Byte''', more precise an '''Octet''', is a unit of measurement of information storage, consisting of '''eigh..."2018-05-25T15:07:06Z<p>Created page with "'''<a href="/Main_Page" title="Main Page">Home</a> * <a href="/Programming" title="Programming">Programming</a> * <a href="/Data" title="Data">Data</a> * Byte''' A '''Byte''', more precise an '''Octet''', is a unit of measurement of information storage, consisting of '''eigh..."</p>
<p><b>New page</b></p><div>'''[[Main Page|Home]] * [[Programming]] * [[Data]] * Byte'''<br />
<br />
A '''Byte''', more precise an '''Octet''', is a unit of measurement of information storage, consisting of '''eight''' [[Bit|bits]]. In most computer architectures it is the granularity of memory addresses, containing 8-bit numbers, 256 different symbols - interpreted as signed or unsigned numbers, [https://en.wikipedia.org/wiki/ASCII ASCII] characters or machine code. Processors provide byte-wise arithmetical and logical units. [[x86]] and [[x86-64]] can address the two lower bytes of each 32 or 64 bit register, for instance AL and AH from EAX or RAX. [[SIMD and SWAR Techniques|SIMD]] instruction sets like [[MMX]], [[AltiVec]] and [[SSE2]] provide operations on vectors of eight or sixteen bytes inside appropriate SIMD-registers.<br />
<br />
The programming languages [[C]] and [[Cpp|C++]] define a byte as a "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment". <br />
<br />
=Char=<br />
The [[C]]-datatype '''unsigned char''' covers one byte and has a numerical range of 0 to 255. The primitive '''char''' in [[Java]] is a signed byte, and ranges from -128 to +127. Same is likely true for signed char in C, though [https://en.wikipedia.org/wiki/Two%27s_complement two's complement] is not strictly specified. Same is true for signed right shifts, where [[x86]] performs shift arithmetical right, but other processors and their compilers possibly shift in always zeros. Bytes are therefor often type defined as '''unsigned char''' in C:<br />
<pre><br />
typedef unsigned char BYTE;<br />
</pre><br />
[[Mailbox]] chess programs often use an [[Array|array]] of bytes for a dense [[Board Representation]], where each byte contains [[Pieces#PieceCoding|piece- or empty square code]] for each indexed [[Squares|square]]. A Byte is also sufficient to store usual (0..63), or [[0x88]] board coordinates. A byte can contain a rank of a [[Bitboards|bitboard]]. For pawn-structure issues, [[Pawns and Files (Bitboards)#Fileset|filesets]] are a dense set-wise representation to cover boolean properties for each [[Files|file]].<br />
<br />
A byte can be written with two hexadecimal digits, 0x00 to 0xff in [[C]] or [[Java]]. Take care and compiler warnings serious, if wider types are assigned to bytes - since all upper bits are lost, if wider types are outside the valid signed or unsigned range.<br />
<br />
=SWAR Bytes=<br />
To apply 'add' or 'sub' on vectors of bytes (or any arbitrary structure) [[SIMD and SWAR Techniques#SWAR|SWAR-wise]] within a 32-bit or 64-bit register, we have to take care carries and borrows don't wrap around. Thus we apply a mask of all most significant bits (H) and 'add' in two steps, one 'add' with MSB clear and one add modulo 2 aka 'xor' for the MSB itself. For byte-wise math of a vector of four bytes inside a 32-bit register, H is 0x80808080 and L is 0x01010101.<br />
<pre><br />
SWAR add z = x + y<br />
z = ((x &~H) + (y &~H)) ^ ((x ^ y) & H)<br />
<br />
SWAR sub z = x - y<br />
z = ((x | H) - (y &~H)) ^ ((x ^~y) & H)<br />
<br />
SWAR average z = (x+y)/2 based on x + y = (x^y) + 2*(x&y)<br />
z = (x & y) + (((x ^ y) & ~L) >> 1)<br />
</pre><br />
<br />
=See also= <br />
* [[Byte Magazine]]<br />
* [[Nibble]]<br />
* [[Pawns and Files (Bitboards)#Fileset|Filesets]]<br />
* [[First Rank Attacks]]<br />
* [[Word]]<br />
* [[Double Word]]<br />
* [[Quad Word]]<br />
* [[SIMD and SWAR Techniques#SWAR|SWAR]]<br />
<br />
=External Links= <br />
* [https://en.wikipedia.org/wiki/Byte Byte from Wikipedia]<br />
* [https://en.wikipedia.org/wiki/Octet_%28computing%29 Octet from Wikipedia]<br />
<br />
'''[[Data|Up one Level]]'''</div>GerdIsenberg