OC iOS How to convert BCD code to iOS acsii code __ios

Source: Internet
Author: User

Author: Zhu Ke

Email: zhukefeng@iboxpay.com

Reprint please indicate the source: HTTP://BLOG.CSDN.NET/LINUX_ZKF


nsstring* ASCIICONVERTFROMBCD (NSString *bcdstring)

{

int len = bcdstring.length;

Char pdupack[len/2+1], *pdustr;

Bzero (Pdupack, len/2+1);


PDUSTR = (char *) [bcdstring cstringusingencoding:nsutf8stringencoding];

for (int i=0 i <len; i+=2) {

Char Tempchar;

Tempchar = Pdustr[i];

if ((Tempchar <= ' 9 ') && (Tempchar >= ' 0 ')) {

Tempchar = Tempchar & 0x0f;

}

else {

Tempchar = (Tempchar & 0x0f) + 9;

}

PDUPACK[I/2] = Tempchar;

Tempchar = pdustr[i+1];

if ((Tempchar <= ' 9 ') && (Tempchar >= ' 0 ')) {

Tempchar = Tempchar & 0x0f;

}

else {

Tempchar = (Tempchar & 0x0f) + 9;

}

PDUPACK[I/2] = ((PDUPACK[I/2] << 4) & 0xf0) + Tempchar;

}

nsstring* retstring = [[NSString alloc] Initwithcstring:pdupack encoding:nsutf8stringencoding];

return retstring;

}

Related Article

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.