hello everyone,
Previously i have posted a question about gsm PDU format where i could not decode PDU characters to ASCII value.
Here is the link for that: https://forum.allaboutcircuits.com/threads/gsm-pdu-decoding-algorithm-behaves-weirdly.141855/
But now i have modified the code and it recovers by previous problem but arises a new problem.
when i provide input to my algorithm in pdu format for symbols like `~!@#$%^&*()-_=+:;"'{[}]<,>.?/ i do not get any output.
Here is my code:
The code works fine for any number of charcter i provide but characters should be alphnumeric.. only alphabets and numbers.. but i want this algorithm to decode symbols also. but it doesn't. Can you suggest me where m i going wrong. What are the mistakes i'm making. Please help.
Thanks in advance.
Any Help will be really Helpful.
Previously i have posted a question about gsm PDU format where i could not decode PDU characters to ASCII value.
Here is the link for that: https://forum.allaboutcircuits.com/threads/gsm-pdu-decoding-algorithm-behaves-weirdly.141855/
But now i have modified the code and it recovers by previous problem but arises a new problem.
when i provide input to my algorithm in pdu format for symbols like `~!@#$%^&*()-_=+:;"'{[}]<,>.?/ i do not get any output.
Here is my code:
C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void OriginalHex(int *buffer,int size,char *string)
{
int i;
for (i=0;string[i]!='\0';i++)
{
if(string[i] >= '0' && string[i] < 'A')
buffer[i] = string[i] - '0';
else if (string[i] >= 'A')
buffer[i] = string[i] - 'A' + 10;
}
}
void PackingTheHex(int *hex,int size,int *string)
{
int i=0,j=0;
for (i=0,j=0;i<size;i+=2,j++)
hex[j] = string[i]<<4 | string[i+1];
}
void HexToDec(int *newHex,int len,int *string)
{
int i=0,j,temp=0x00,l;
int mask = 0xFF;
for (i=0,j=0,l=0;i<len/2;i++,j++,l++)
{
if(j==8)
{
newHex[l] = temp & 0x7f;
temp = temp>>7;
j=1;
l+=1;
}
newHex[l] = ((string[i] & (mask>>j+1)) << j) | temp;
temp = string[i] >> (7-j);
}
}
int main(void)
{
int i;
char userString[512];
printf("\nEnter 8-Bit Packed Form String: ");
gets(userString);
printf("\n\nYou have Entered %s",userString);
int stringLen = strlen(userString);
printf("\n\nOringinal Hex: ");
int *hex = (int*)malloc(sizeof(int)*stringLen);
OriginalHex(hex,stringLen,userString);
for (i=0;i<stringLen;i++)
printf("%d ",hex[i]);
printf("\n\nPacking The Hex: ");
int *newHex = (int*)malloc(sizeof(int)*stringLen);
PackingTheHex(newHex,stringLen,hex);
for (i=0;i<stringLen/2;i++)
printf("%d ",newHex[i]);
free(hex);
printf("\n\nHex to Decimal Values are: ");
int *decHex = (int*)malloc(sizeof(int)*stringLen);
HexToDec(decHex,stringLen,newHex);
stringLen = stringLen + stringLen/8;
for (i=0;i<stringLen/2+1;i++)
printf("%d ",decHex[i]);
free(newHex);
char *ASCIIchar = (char*)malloc(sizeof(char)*stringLen);
for (i=0;i<stringLen/2+1;i++)
ASCIIchar[i] = (char)decHex[i];
ASCIIchar[i] = '\0';
printf("\n\nOriginal sentence is: %s",ASCIIchar);
free(decHex);
free(ASCIIchar);
}
Thanks in advance.
Any Help will be really Helpful.