ASC Conversion BCD,ASC2BCD

Source: Internet
Author: User
Tags numeric value strlen

int ASC2BCD (const char* szasc,byte* szbdc)
{
	int szasclen=strlen (SZASC);
	BYTE * BPBCD = new BYTE[SZASCLEN/2];
	int nss=0,nou=0;
	for (int x=szasclen-1;x>=0;x--)
	{
		//Remove a numeric value from the string
		char char_1=* (szasc+x);
		Remove BCD code
		int NBDC;
		if (char_1! = '. ')		Nbdc= (char_1 & 0xF);
		else					nbdc=14;
		
		if ((++nou) &0x01)
			bpbcd[nss]= (NBDC << 4);
		else
			bpbcd[nss++] + = NBDC;
		
	}
	int nbit=0;
	if (nou%2==0)	nbit=nou/2-1;
	else			NBIT=NOU/2;
	for (int y=0;y<=nou/2;y++)
	{
		szbdc[y]= (Bpbcd[nbit-y] << 4);
		szbdc[y]+= (Bpbcd[nbit-y] >> 4);
	}
	return nBit;	memcpy (szbdc,bpbcd,sizeof (BPBCD));
}

void Cdottestdlg::onbutton1 () 
{
	char sztest[]={"123456789123456789.789"};
	
	int S=strlen (sztest);

	BYTE * szan=new BYTE[S/2];
	int W=ASC2BCD (Sztest,szan);
	for (int x=0;x<=w;)
		TRACE ("%x", szan[x++]);
}


Case:
Output: The E7 89,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.