This class is able to serialize and unserialize binary data, so you can read files generated with C, pascal, etc as well as generate such data. It's also able to handle the byte order (big/little endian) and supports the following types: signed integer (small 8 bits, short 16 bits, int 32 bits), unsigned integer (byte 8 bits, word 16 bits, dword 32 bits) and floating point (IEEE754 float 32 bits and double 64 bits). Constructor BinaryParser([bigEndian: Boolean = false], [allowExceptions: Boolean = false]) Generates an instance of BinaryParser. bigEndian if true, the class will assume the bigEndian format for the input and output, otherwise, it will assume the little endian format. allowExceptions if true, when number=>binary conversion error occur an exception will be raised (which can be caught through a "try..except" block) Properties BinaryParser.bigEndian: Boolean if true, the class will assume the bigEndian format for the input and output, otherwise, it will assume the little endian format. BinaryParser.allowExceptions: Boolean if true, when number=>binary conversion error occur an exception will be raised (which can be caught through a "try..except" block) Gerenic Methods BinaryParser.decodeFloat(data: String, precisionBits: Integer, exponentBits: Integer): Float Decodes a string containing the binary representation of a number in the IEEE-754 pattern and returns the number or the following special values: NaN, +Infinity, -Infinity. data string containing the binary representation of the number (must contain at least "ceil((exponentBits + precisionBits + 1) / 8)" bytes) precisionBits amount of bits that specifies the precision/mantisse exponentBits amount of bits that specifies the exponent BinaryParser.encodeFloat(number: Float, precisionBits: Integer, exponentBits: Integer): String Encodes a number into the IEEE-754 pattern and returns the binary representation of it in a string containing "ceil((exponentBits + precisionBits + 1) / 8)" bytes. number number to be converted precisionBits amount of bits that specifies the precision/mantisse exponentBits amount of bits that specifies the exponent BinaryParser.decodeInt(data: String, bits: Integer, signed: Boolean): Integer Decodes a string containing binary data and returns the number that it represents. data string containing the binary representation of the number (must contain at least "ceil(bits / 8)" bytes) bits amount of bits that specifies the quantity of numbers that can be represented signed indicates if the number must be decoded with signal or without signal BinaryParser.encodeInt(number: Int, bits: Integer, signed: Boolean): Integer Encodes an integer number and returns it's binary representation on a string containing "ceil(bits / 8)" bytes. number number to be converted bits amount of bits that specifies the quantity of numbers that can be represented signed indicates if the number must be encoded with signal or without signal Methods (Float Point) BinaryParser.toFloat(data: String): Float Returns a number or a special value (NaN, +Infinity, -Infinity). data string containing at least 4 bytes BinaryParser.fromFloat(number: Float): String Returns the binary representation of a number in a string, the method can raise exceptions if the property "allowExceptions" is true and the number is an special value (NaN, +Infinity, -Infinity) or if it can't be represented (overflow, underflow). number number to be converted to binary BinaryParser.toDouble(data: String): Float Returns a number or a special value (NaN, +Infinity, -Infinity). data string containing at least 8 bytes BinaryParser.fromDouble(number: Float): String Returns the binary representation of a number in a string, the method can raise exceptions if the property "allowExceptions" is true and the number is an special value (NaN, +Infinity, -Infinity) or if it can't be represented (overflow, underflow). number number to be converted to binary Methods (Integer Numbers) BinaryParser.toSmall(data: String): Integer Receives a string and returns its integer value with signal. data string containing at least 1 bytes BinaryParser.fromSmall(number: Integer): String Receives an integer and returns its binary representation in a string with 1 byte, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary BinaryParser.toByte(data: String): Integer Receives a string and returns its integer value without signal. data string containing at least 1 bytes BinaryParser.fromByte(number: Integer): String Receives an integer and returns its binary representation in a string with 1 byte, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary, the class ignores if the number is negative or not (in the two's complement, "-1" is represented in the same way as "255") BinaryParser.toShort(data: String): Integer Receives a string and returns its integer value with signal. data string containing at least 2 bytes BinaryParser.fromShort(number: Integer): String Receives an integer and returns its binary representation in a string with 2 bytes, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary BinaryParser.toWord(data: String): Integer Receives a string and returns its integer value without signal. data string containing at least 2 bytes BinaryParser.fromWord(number: Integer): String Receives an integer and returns its binary representation in a string with 2 bytes, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary, the class ignores if the number is negative or not (in the two's complement, "-1" is represented in the same way as "255") BinaryParser.toInt(data: String): Integer Receives a string and returns its integer value with signal. data string containing at least 4 bytes BinaryParser.fromInt(number: Integer): String Receives an integer and returns its binary representation in a string with 4 bytes, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary BinaryParser.toDWord(data: String): Integer Receives a string and returns its integer value without signal. data string containing at least 4 bytes BinaryParser.fromDWord(number: Integer): String Receives an integer and returns its binary representation in a string with 4 bytes, the method can raise an exception if the number is too big to be represented and the property "allowExceptions" is true. number number to be converted to binary, the class ignores if the number is negative or not (in the two's complement, "-1" is represented in the same way as "255")