Logo Search packages:      
Sourcecode: hamlib version File versions  Download package

unsigned char* HAMLIB_API to_bcd ( unsigned char  bcd_data[],
unsigned long long  freq,
unsigned  bcd_len 

Convert from binary to 4-bit BCD digits, little-endian.

Convert a long long (e.g. frequency in Hz) to 4-bit BCD digits, packed two digits per octet, in little-endian order (e.g. byte order 90 78 56 34 12 for 1234567890 Hz).

bcd_len is the number of BCD digits, usually 10 or 8 in 1-Hz units, and 6 digits in 100-Hz units for Tx offset data.

Hope the compiler will do a good job optimizing it (esp. w/the 64bit freq)

Returns a pointer to (unsigned char *)bcd_data.

See also:

Definition at line 73 of file misc.c.

      int i;
      unsigned char a;

      /* '450'/4-> 5,0;0,4 */
      /* '450'/3-> 5,0;x,4 */

      for (i=0; i < bcd_len/2; i++) {
            a = freq%10;
            freq /= 10;
            a |= (freq%10)<<4;
            freq /= 10;
            bcd_data[i] = a;
      if (bcd_len&1) {
            bcd_data[i] &= 0xf0;
            bcd_data[i] |= freq%10; /* NB: high nibble is left uncleared */

      return bcd_data;

Generated by  Doxygen 1.6.0   Back to index