BALTECH SDK wrapper functions reference

§ BcdToBin

bool BcdToBin

Converts a BCD number (must only contain nibbles 0-9, not A-F) to a binary number.

Input and output data are MSB encoded. 0x01 0x23 0x45 => 0x30 0x39

Note the following restrictions:

  • The largest BCD number this filter can convert is the following 39-digit number (20 bytes): 0x03 0x40 0x28 0x23 0x66 0x92 0x09 0x38 0x46 0x34 0x63 0x37 0x46 0x07 0x43 0x17 0x68 0x21 0x14 0x55
  • The destination length (in bytes) is calculated by multiplying the source data length by 0.83048 and rounding down to the next byte boundary.

If the source data's binary representation is longer than the calculated destination length, the conversion fails. Example: Source data (BCD): 0x12 0x34 Source data length: 2 bytes (4 digits) Converted data (binary): 0x04 0xD2 Actual destination data length: 2 bytes Calculated destination data length: int(2 bytes * 0.83048) = 1 byte

The maximum BCD number convertible for a given source data length can be calculated as follows: 2 ^ {int(src_len * 0.83048) * 8} - 1

For example, for a 2-byte BCD number, the largest convertible value is 255: 0x02 0x55 => 0xFF

If the source data may exceed the maximum convertible BCD number, insert an additional leading zero byte in front of it: 0x00 0x12 0x34 => 0x04 0xD2

Definition at line 309 of file typedefs.h.