Introduction.

There are three different drawing interchange file formats:
- ASCII DXF
- Binary DXF
- Simpler binary DXB

Binary DXF File Format.

The binary file is a compressed version of the ASCII form, but occupies about 25% less size on disk.
Binary is a compact format that can be written and read more quickly by computer software, however to have a minimum file size the better option is to write a normal ascii dxf file and then use an archiver (like zip. 7zip, tar or other), obviously this compessing/decompressing make read and write very slow.
Not all software can read or write the binary format of DXF.
Unlike the ASCII DXF, in the binary format is impossible write a comment (group code 999).
The first writable binary form is the DXF R10, before this version only the ASCII form existed.

The file always start with a header of 22 Bytes:
AutoCAD Binary DXF<CR><LF><SUB><NULL>
Than follow the group code and the value, like the ASCII format, but represented in binary form:
The group code is a 1 byte binary value, since R14 it is a 2 byte binary value.
If the value is an integer, it is written in a 2 byte integer (with the least significant byte followed by the most significant byte).
If the value is a double, it is written in a 8 byte IEEE form (with the least significant byte followed by the most significant byte).
If the value is a string of char, it is written like an ASCII string but with a <NULL> byte (0) at the end.

Unlike the ASCII format, the extended data group codes have a 1 byte (with the value 255) pre group code, then a 2 byte integer with the correct group code, then the value.
If the extended data value is a long value, there are 4 bytes data.
If the extended data value is a string of characters, there are a 1 unsigned byte, followed by the number of bytes.


DXB File Format.

A third form of DXF known as DXB (drawing interchange binary) is an even simpler binary format.
This file has a different file extension (.dxb) and it's substantial different format, with a different syntax.

The file always start with a header of 19 Bytes:
AutoCAD DXB 1.0<CR><LF><^Z><NULL>
DXB files have only a very limited number of entities: line, point, circle, arc, trace, solid, polyline, and 3D face.