Thank you petdocvmd for the VB.Net Code. :D I converted and used it in a C# application to read and write the Radio Frequencies.
As a token of my appreciation here is the C# version of the code:
public static class MyConvert
{
// This class serves to separate out conversion functions, etc
public static short DECtoBCD(int intDEC)
{
short rval;
// This function takes the decimal equivalent of a BCD and returns the BCD
short mThous;
short mHund;
short mTen;
short mOne;
mThous = Convert.ToInt16((intDEC & 61440) / 4096 * 1000);
mHund = Convert.ToInt16((intDEC & 3840) / 256 * 100);
mTen = Convert.ToInt16((intDEC & 240) / 16 * 10);
mOne = Convert.ToInt16((intDEC & 15));
rval = Convert.ToInt16(mThous + mHund + mTen + mOne);
return rval;
}
public static short BCDtoDEC(int intBCD)
{
short rval;
// This function takes a BCD and returns decimal equivalent
short mThous;
short mHund;
short mTen;
short mOne;
mThous = Convert.ToInt16((intBCD / 1000) * 1000);
mHund = Convert.ToInt16(((intBCD - mThous) / 100) * 100);
mTen = Convert.ToInt16(((intBCD - mThous - mHund) / 10) * 10);
mOne = Convert.ToInt16((intBCD - mThous - mHund - mTen));
rval = Convert.ToInt16(mThous / 1000 * 4096 + mHund / 100 * 256 + mTen / 10 * 16 + mOne);
return rval;
}
}
The Class is declared Static so one does not need to create an instance of the class.
fritzw