<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Binary Data Representation
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../cat+en">Up</a>&nbsp;
<a href="conv+en">Previous</a>&nbsp;
<a href="datatypes+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Binary Data Representation
</h1>
The <a href="../lang/read+en">READ</a> and <a href="../lang/write+en">WRITE</a> instructions allow to read and write binary representation of <a href="../def/gambas+en">Gambas</a> datatypes values.
<p>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr><th>
Datatype
</th><th>
Size
</th><th>
Representation
</th></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/boolean+en">Boolean</a>
</td><td valign="top">
1 byte
</td><td valign="top">
<tt>0</tt> for <a href="../lang/false+en">FALSE</a>, <tt>255</tt> for <a href="../lang/true+en">TRUE</a>.
</td></tr>
<tr><td valign="top">
<a href="../lang/type/byte+en">Byte</a>
</td><td valign="top">
1 byte
</td><td valign="top">
The data value in binary.
</td></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/short+en">Short</a>
</td><td valign="top">
2 bytes
</td><td valign="top">
The data value in binary.
</td></tr>
<tr><td valign="top">
<a href="../lang/type/integer+en">Integer</a>
</td><td valign="top">
4 bytes
</td><td valign="top">
The data value in binary.
</td></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/long+en">Long</a>
</td><td valign="top">
8 bytes
</td><td valign="top">
The data value in binary.
</td></tr>
<tr><td valign="top">
<a href="../lang/type/single+en">Single</a>
</td><td valign="top">
4 bytes
</td><td valign="top">
The data value in binary.
</td></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/float+en">Float</a>
</td><td valign="top">
8 bytes
</td><td valign="top">
The data value in binary.
</td></tr>
<tr><td valign="top">
<a href="../lang/type/date+en">Date</a>
</td><td valign="top">
8 bytes
</td><td valign="top">
The date and time as two four-bytes integers.
</td></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/string+en">String</a>
</td><td valign="top">
Variable
</td><td valign="top">
If you do not specified the string length, the string length is written
just before the string data:
<ul>
<li>One byte is written if the string length is lower or equal than 127 characters.
<li>Two bytes are written if the string length is between 128 and 16383 characters.
<li>Four bytes are written if the string length is between 16384 and 1073741824 characters.
<li>Longer strings cannot be written at the moment.
</ul>

</td></tr>
<tr><td valign="top">
<a href="../lang/null+en">NULL</a>
</td><td valign="top">
1 byte
</td><td valign="top">
Null values and null strings are written as a single <tt>0</tt> byte.
</td></tr>
<tr class="dark"><td valign="top">
<a href="../lang/type/variant+en">Variant</a>
</td><td valign="top">
Variable
</td><td valign="top">
When writing a variant value, a byte indicating the value datatype is written before.
The value itself is written according to this table.
</td></tr>
</table>
<p>
The endianness of the binary data is the endianness of the <a href="../def/stream+en">stream</a>.
<p>
<hr><b>See also</b><br>
<a href="../lang/read+en">READ</a>&nbsp; <a href="../lang/write+en">WRITE</a>&nbsp; <a href="../comp/gb/stream/byteorder+en">ByteOrder</a>&nbsp;

</div>
</body>
</html>

