How to get the corresponding characters by binary ASCII (010101)

Source: Internet
Author: User

Requirements: Sometimes in the communication of some engineering, the receiving end receives the ASCII code (0101) is often the character information, this string of things stored in an int array (int a[7]), this time how to parse the corresponding character?

Answer:

#include <stdio.h>

#include <math.h>


int main ()
{//0 1 2 3 4 5 6
int a[7]={0,0,0,0,1,1,0};"0" ASCII code, note the reverse
int i; Loop variable


Print ASCII code
for (i=6; i>=0; i--)
printf ("a[%d]=%d", I,a[i]);
printf ("\ n");


Computes the decimal value of the ASCII code
int sum=0;
for (i=6; i>=0; i--)
Sum+=a[i] * POW (2 * a[i],i);

printf ("%d--->%c", sum,sum); Output the decimal ASCII code and the corresponding characters, respectively


return 0;
}

How to get the corresponding characters by binary ASCII (010101)

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.