# Platform Independent Data Types

Topics
Overview | Type Defines
INT32 Class | UINT32 Class
INT16 Class | UINT16 Class
FLOAT64 Class | Exceptions

Overview

The platform independent data type classes are used to represent integers and floating point values independently of the operating system or hardware platform used. They were created to overcome the big and little endian byte ordering problems encountered when writing integer and floating point values to a common database file accessed by several different types of machines.

The term "endian" is used to describe the order in which multi-byte numbers are stored in the computer's memory. This is specific to each microprocessor. The Intel x86 family is little-endian, meaning that the lowest-order byte is stored first. Hewlett-Packard's PA-RISC and Sun's SuperSPARC are big-endian, meaning the highest-order byte is stored first. The Silicon Graphics MIPS and IBM/Motorola Power PC processors are both little and big endian (bi-endian).

Value | Big-Endian | Little-Endian
0x12345678 | 0x12345678 | 0x78563412
0x1234 | 0x1234 | 0x3412
0x5678 | 0x5678 | 0x7856
"ABC" | 41 42 43 | 41 42 43

With big-endian ordering, the address of the multi-byte value is its most significant byte (its big end.) With little-endian ordering, the address of the multi-byte value is its least significant byte (its little end.) Character stings are stored in memory exactly as they appear regardless of the byte ordering used. In a data structure the order of bytes in memory will differ depending on the byte ordering and the particular data type used. If the contents of a data structure are written to disk, the byte ordering will affect the file if it is moved to another platform.

Type Defines

The "dtypes.h" file contains type definitions and constants used to maintain compatibility between the built-in data type sizes on various compilers. The following is a list of the type definitions used in the VBD class library:

typedef char __SBYTE__;

// 8-bit signed value.

typedef unsigned char __UBYTE__;

// 8-bit unsigned value.

typedef int __WORD__;

// 32 bit word size (4 bytes).

typedef unsigned __UWORD__;

// Unsigned 32 bit word size (4 bytes).

typedef long __LWORD__;

// Long word size (4 bytes).

typedef unsigned long __ULWORD__;

// Unsigned long word size (4 Bytes).

typedef short __SWORD__;

// 16 bit short word size (2 bytes).

typedef unsigned short __USWORD__;

// 16 bit unsigned short word size (2 bytes).

typedef double __DPFLOAT__;

// Double precision floating point value (8 bytes).

INT32 Class

The INT32 class is used to represent 32-bit signed integers independently of the operating system or hardware platform used. It works by separating a 32-bit value into four separate byte values and reordering the bytes lowest-order to highest-order. An INT32 type has a base 10 positive limit of 2,147,483,647 and a negative limit of 2,147,483,648.

Member functions:

INT32::INT32(__LWORD__ val = 0)

- Class constructor responsible for separating the 32-bit value into four separate byte values when the object is constructed.

INT32::INT32(const INT32& ob)

- Class copy constructor that copies the byte values from the object specified to the object being constructed.

INT32& INT32::operator=(const INT32& ob)

- Assignment operator that assigns the byte values from the object specified to the object that invoked the call. Returns the object in question and will support chained assignment.

INT32& INT32::operator=(const __LWORD__ ob)

- Assignment operator that accepts an __LWORD__ 32-bit value. This assignment operator will separate the 32-bit value specified into four separate byte values and pack the bytes into the object that invoked the call. Returns the object in question and will support chained assignment.

void INT32::UnPackBits(__LWORD__ val)

- Public member function responsible for separating a 32-bit value into four separate byte values. It works by masking the individual byte values with a bitwise AND, then right shifting the bytes into a four-byte array.

__LWORD__ INT32::PackBits() const

- Public member function responsible for reordering the bytes from lowest-order to highest-order. It works by separating the four-byte array into four separate __LWORD__ values. These values are masked with a bitwise AND, left shifted into position, and then added together to form a single 32-bit value that will remain consistent regardless of the original byte ordering used.

INT32::operator __LWORD__() const

- Conversion function used to convert a INT32 type into a __LWORD__ type.

Overloaded operators:

The INT32 class has several overloads of arithmetic and comparison operators. Each version is overloaded for the following data types: INT32, __LWORD__, __ULWORD__, __WORD__, __SWORD__, __ULWORD__, __USWORD__, __SBYTE__, and __UBYTE__.

Arithmetic operators that modify their operand:

- (Postfix and Prefix) operator++
- (Postfix and Prefix) operator--
- operator+=
- operator-=
- operator*=
- operator/=

Exceptions:
CDivideByZero()

Comparison operators:

- operator==
- operator!=
- operator<
- operator>
- operator<=
- operator>=

UINT32 Class

The UINT32 class is used to represent 32-bit unsigned integers independently of the operating system or hardware platform used. It works by separating a 32-bit value into four separate byte values and reordering the bytes lowest-order to highest-order. An UINT32 type has a base 10 limit of 4,294,967,295.

Member functions:

UINT32::UINT32(__ULWORD__ val = 0)

- Class constructor responsible for separating the 32-bit value into four separate byte values when the object is constructed.

UINT32::UINT32(const UINT32& ob)

- Class copy constructor that copies the byte values from the object specified to the object being constructed.

UINT32& UINT32::operator=(const UINT32& ob)

- Assignment operator that assigns the byte values from the object specified to the object that invoked the call. Returns the object in question and will support chained assignment.

UINT32& UINT32::operator=(const __ULWORD__ ob)

- Assignment operator that accepts a __ULWORD__ 32-bit value. This assignment operator will separate the 32-bit value specified into four separate byte values and pack the bytes into the object that invoked the call. Returns the object in question and will support chained assignment.

void UINT32::UnPackBits(__ULWORD__ val)

- Public member function responsible for separating a 32-bit value into four separate byte values. It works by masking the individual byte values with a bitwise AND, then right shifting the bytes into a four-byte array.

__ULWORD__ UINT32::PackBits() const

- Public member function responsible for reordering the bytes from lowest-order to highest-order. It works by separating the four-byte array into four separate __ULWORD__ values. These values are masked with a bitwise AND, left shifted into position, and then added together to form a single 32-bit value that will remain consistent regardless of the original byte ordering used.

UINT32::operator __ULWORD__() const

- Conversion function used to convert a UINT32 type into a __ULWORD__ type.

Overloaded operators:

The UINT32 class has several overloads of arithmetic and comparison operators. Each version is overloaded for the following data types: UINT32, __LWORD__, __ULWORD__, __WORD__, __SWORD__, __ULWORD__, __USWORD__, __SBYTE__, and __UBYTE__.

Arithmetic operators that modify their operand:

- (Postfix and Prefix) operator++
- (Postfix and Prefix) operator--
- operator+=
- operator-=
- operator*=
- operator/=

Exceptions:
CDivideByZero()

Comparison operators:

- operator==
- operator!=
- operator<
- operator>
- operator<=
- operator>=

INT16 Class

The INT16 class is used to represent 16-bit signed integers independently of the operating system or hardware platform used. It works by separating 16-bit values into two separate byte values and reordering the bytes lowest-order to highest-order. An INT16 type has a base 10 positive limit of 32,767 and a negative limit of 32,768.

Member functions:

INT16::INT16(__SWORD__ val = 0)

- Class constructor responsible for separating the 16-bit value into two separate byte values when the object is constructed.

INT16::INT16(const INT16& ob)

- Class copy constructor that copies the byte values from the object specified into the object being constructed.

INT16& INT16::operator=(const INT16& ob)

- Assignment operator that assigns the byte values from the object specified to the object that invoked the call. Returns the object in question and will support chained assignment.

INT16& INT16::operator=(const __SWORD__ ob)

- Assignment operator that accepts a __SWORD__ 16-bit value. This assignment operator will separate the16-bit value specified into two separate byte values and pack the bytes into the object that invoked the call. Returns the object in question and will support chained assignment.

void INT16::UnPackBits(__SWORD__ val)

- Public member function responsible for separating a 16-bit value into two separate byte values. It works by masking the individual byte values with a bitwise AND, then right shifting the bytes into a two-byte array.

__SWORD__ INT16::PackBits() const

- Public member function responsible for reordering the bytes from lowest-order to highest-order. It works by separating the two-byte array into two separate __SWORD__ values. These values are masked with a bitwise AND, left shifted into position, and then added together to form a single 16-bit value that will remain consistent regardless of the original byte ordering used.

INT16::operator __SWORD__() const

- Conversion function used to convert an INT16 type into a __SWORD__ type.

Overloaded operators:

The INT16 class has several overloads of arithmetic and comparison operators. Each version is overloaded for the following data types: INT16, __LWORD__, __ULWORD__, __WORD__, __SWORD__, __ULWORD__, __USWORD__, __SBYTE__, and __UBYTE__.

Arithmetic operators that modify their operand:

- (Postfix and Prefix) operator++
- (Postfix and Prefix) operator--
- operator+=
- operator-=
- operator*=
- operator/=

Exceptions:
CDivideByZero()

Comparison operators:

- operator==
- operator!=
- operator<
- operator>
- operator<=
- operator>=

UINT16 Class

The UINT16 class is used to represent 16-bit unsigned integers independently of the operating system or hardware platform used. It works by separating a 16-bit value into two separate byte values and reordering the bytes lowest-order to highest-order. An UINT16 type has a base 10 positive limit of 65,535.

Member functions:

UINT16::UINT16(__USWORD__ val = 0)

- Class constructor responsible for separating the 16-bit value into two separate byte values when the object is constructed.

UINT16::UINT16(const UINT16& ob)

- Class copy constructor that copies the byte values from the object specified into the object being constructed.

UINT16& UINT16::operator=(const UINT16& ob)

- Assignment operator that assigns the byte values from the object specified to the object that invoked the call. Returns the object in question and will support chained assignment.

UINT16& UINT16::operator=(const __USWORD__ ob)

- Assignment operator that accepts a __USWORD__ 16-bit value. This assignment operator will separate the 16-bit value specified into two separate byte values and pack the bytes into the object that invoked the call. Returns the object in question and will support chained assignment.

void UINT16::UnPackBits(__USWORD__ val)

- Public member function responsible for separating a 16-bit value into two separate byte values. It works by masking the individual byte values with a bitwise AND, then right shifting the bytes into a two-byte array.

__USWORD__ UINT16::PackBits() const

- Public member function responsible for reordering the bytes from lowest-order to highest-order. It works by separating the two-byte array into two separate __USWORD__ values. These values are masked with a bitwise AND, left shifted into position, and then added together to form a single 16-bit value that will remain consistent regardless of the original byte ordering used.

UINT16::operator __USWORD__() const

- Conversion function used to convert a UINT16 type into a __USWORD__ type.

Overloaded operators:

The UINT16 class has several overloads of arithmetic and comparison operators. Each version is overloaded for the following data types: UINT16, __LWORD__, __ULWORD__, __WORD__, __SWORD__, __ULWORD__, __USWORD__, __SBYTE__, and __UBYTE__.

Arithmetic operators that modify their operand:

- (Postfix and Prefix) operator++
- (Postfix and Prefix) operator--
- operator+=
- operator-=
- operator*=
- operator/=

Exceptions:
CDivideByZero()

Comparison operators:

- operator==
- operator!=
- operator<
- operator>
- operator<=
- operator>=

FLOAT64 Class

The FLOAT64 class is used to represent 64-bit signed double precision floating point values independently of the operating system or hardware platform used. A double precision floating point number stores binary info within a total of 64 bits. The first bit contains the sign of the mantissa (0 for positive and 1 for negative.) The next 11bits store the exponent, and the remaining 52 bits provide the mantissa, giving an approximate decimal precision of 15 digits.

The FLOAT64 class works by separating a 64-bit value into eight separate byte values and reordering the bytes highest-order to lowest-order. A FLOAT64 type has a positive limit of 1.7E+308 and a negative limit of 1.7E-308 with 15-digit precision. NOTE: In order to maintain the correct byte ordering on PC based, Intel x86 family, systems the __X86__ macro must be defined at compile time. The __X86__ macro instructs the FLOAT64 class to reverse the byte ordering in order to remain consistent with the big-endian byte ordering.

Member functions:

FLOAT64::FLOAT64(__DPFLOAT__ val = 0)

- Class constructor responsible for separating the 64-bit value into eight separate byte values when the object is constructed.

FLOAT64::FLOAT64(const FLOAT64& ob)

- Class copy constructor that copies the byte values from the object specified into the object being constructed.

FLOAT64& FLOAT64::operator=(const FLOAT64& ob)

- Assignment operator, assigns the byte values from the object specified to the object that invoked the call. Returns the object in question and will support chained assignment.

FLOAT64& FLOAT64::operator=(const __DPFLOAT__ ob)

- Assignment operator that accepts a __DPFLOAT__ 64-bit value. This assignment operator will separate the 64-bit value specified into eight separate byte values and pack the bytes into the object that invoked the call. Returns the object in question and will support chained assignment.

void FLOAT64::UnPackBits(__DPFLOAT__ val)

- Public member function responsible for separating a 64-bit value into eight separate byte values. It works by creating a copy of the __DPFLOAT__ value in memory, typed as a char *, and then copies each byte value from the in-memory copy into the members of an eight byte array. NOTE: In order to maintain the correct byte ordering on PC based, Intel x86 family, systems the __X86__ macro must be defined at compile time. The __X86__ macro instructs the FLOAT64 class to reverse the byte ordering in order to remain consistent with big-endian byte ordering.

__DPFLOAT__ FLOAT64::PackBits() const

- Public member function responsible for reordering the bytes from highest-order to lowest-order. It works by allocating a new __DPFLOAT__ value in memory, and then moving the contents of the eight-byte array into the __DPFLOAT__ value. NOTE: In order to maintain the correct byte ordering on PC based, Intel x86 family, systems the __X86__ macro must be defined at compile time. The __X86__ macro instructs the FLOAT64 class to reverse the byte ordering in order to remain consistent with big-endian byte ordering.

FLOAT64::operator __DPFLOAT__() const

- Conversion function used to convert a FLOAT64 type into a __DPFLOAT__ type.

Overloaded operators:

The FLOAT64 class has several overloads of arithmetic and comparison operators. Each version is overloaded for the following data types: FLOAT64, __DPFLOAT__, __LWORD__, __ULWORD__, __WORD__, __SWORD__, __ULWORD__, and __USWORD__, __SBYTE__, __UBYTE__.

Arithmetic operators that modify their operand:

- (Postfix and Prefix) operator++
- (Postfix and Prefix) operator--
- operator+=
- operator-=
- operator*=
- operator/=

Exceptions:
CDivideByZero()

Comparison operators:

- operator==
- operator!=
- operator<
- operator>
- operator<=
- operator>=

Exceptions

The INT32, UINT32, INT16, UINT16, and FLOAT64 member functions can throw any of the following exceptions if the CPP_EXCEPTIONS macro is defined in the EHandler class at compile time. NOTE: The appropriate try and catch statements within the application must handle each exception or the program will terminate. If the CPP_EXCEPTIONS macro is not defined, the global error hander will signal that an exception has occurred and will terminate the program as defined in the Ehandler::Terminate() function.

CDivideByZero

() - this exception is thrown if an application attempts to divide by zero.

End Of Document