3DSoftware.com > Programming > File Formats > FIN > Page 3
FIN File Format  Page 3
 
Data Elements
 
Some data elements are stored as a single byte each, which stores 8 bits of information per element. An individual data element can also be multiple bytes. For example, a 32-bit number is a 4-byte data element.
 
A data element can also be a nibble. A nibble is a half-byte (4 bits). Two nibbles use 1 byte (8 bits) of storage, three nibbles use 1½ bytes (12 bits) of storage, 4 nibbles use 2 bytes, etc.
 
In nibble streams we sometimes use a data type we call shortshort which is 3 nibbles. Shortshort is a 12-bit number with whole number value in the range [0, 4095] which is more than 4 thousand possible whole numbers.
 
A range of numbers can be specified as intervals with square brackets. The square brackets are standard mathematical notation which indicates that the bounds are included in the interval. For example:  [0, 4095]  means the range can consist of the number 0, or the number 4095, or any of the numbers in between. For whole numbers that means:
0, 1, 2, ...  4093, 4094, 4095
 
For multi-byte integers we support the usual 2-byte and 4-byte integer. We also support what we call a medium unsigned integer (mediumuint) which is 3 bytes. Mediumuint is a 24-bit number that can store a whole number value in the range [0, 16777215] which is more than 16 million possible whole numbers.
 
If you need to support 8-byte (64-bit) integers, simply save them in MSBFIRST byte order (covered in next section) which puts the high 4-byte integer first. All integers are unsigned. Signed integers are represented with biasing or in sign-magnitude form. Complement numbers are not used.
 
Sign-magnitude (also called signed-magnitude) consists of an unsigned number with a leading sign bit in the leading byte of the number. The leading sign bit is clear (0) if the number is positive, or set (1) if the number is negative.
 
There are no pad bytes in FIN files. Data are saved to disk on byte boundaries, not on word boundaries or any other kind of delimiters. However, there can be pad nibbles in the FIN file, to extend nibble streams to byte boundaries. If a nibble stream that will be saved to disk on its own (not as part of a larger nibble stream) is an odd number of nibbles it will be extended with an extra nibble (equal to 0x0) so that it can be saved to disk as a byte stream (2 nibbles per byte).
 
 
MSBFIRST Byte Order
 
Any variable that is multi-byte (such as a 4-byte integer) is stored with most significant byte first. This byte ordering is called “MSBFIRST” or “Network Byte Order.” All multi-byte variables in a FIN file use MSBFIRST byte ordering. The MSBFIRST page has C/C++ source code to read and write a multi-byte number.
 
Byte streams can be written directly to (and read directly from) disk file as you normally do (without special functions), because byte stream elements are not multi-byte. Each element (variable) in a byte array is a single byte.
 
—  Page 3  —
 « Page 2 Contents Page 4 » 
 
Copyright © 2008 by 3D Software. All rights reserved.
3D Software, P.O. Box 221190, Sacramento CA 95822 USA
www.3DSoftware.com     Contact us
Tuesday, 06-Jan-2009 04:46:38 GMT