ccplusplus.com
Learn C, C++ Concepts
Friday, June 15, 2012
ascii to binary conversion in c
/*---------------------------------------------------------------------------------- Function Name: ascii_to_binary Desc : The function converts the ascii value to corresponding binary value . Parameters : pointer to the ascii value. Returns : Converted binary value. Source : http://www.ccplusplus.com/p/c.html Date Created : 10:47 PM 6/15/2012 -----------------------------------------------------------------------------------*/ unsigned char ascii_to_binary(const char *str) { int len=0,tlen=0,i=0; unsigned int binary = 0; len = strlen(str); tlen = len; while(len != 0) { if(str[i]=='0') { //ANALY binary |= (0 << 1); if(i==0) binary = (binary | 0x0); // << 1; else binary = (binary << 1) | 0x0; //DBG } else if(str[i]=='1') { if(i==0) binary = (binary | 0x1); // << 1; else binary = (binary << 1) | 0x1; } len--; i++; }; //ANLYZE binary = binary & ((1 << (tlen-3))-1); return binary; }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment