Logo Search packages:      
Sourcecode: hamlib version File versions

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.

Parameters:
bcd_data 
freq 
bcd_len 
Returns:
bcd_data
Convert a long long (eg. frequency in Hz) to 4-bit BCD digits, packed two digits per octet, in little-endian order. 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)

Definition at line 66 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