This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hex To Decimal

hi all,
i am getting data from serial port so it is in character form

my function is like this

<per>
{
idata char arr[15]={0};
int i,j;

arr[i++]=getkey();
while(( arr[i++] = getCharX())!=0xff && i<11){ //Get Ack package

}
i=(arr[2]/0x10)>0x09?(arr[2]/0x10)+55:(arr[2]/0x10)+48;
j=(arr[2]%0x10)>0x09?(arr[2]%0x10)+55:(arr[2]%0x10)+48;
display(i);
display(j);
}
void display(char s)
{ ...
...
return;
}
</per>

The value is hex which I convert and move into i and j I can see the value properly on LCD but can not perform operation on it as an integer please suggest how i can convert this value into integer
ex- 56 is moved as 5 & 6 into i & j respectively but i want to convert them to decilmal
please help.
Thank you.
Ajay

Parents
  • void BinToDec(unsigned char)
    {
        unsigned char  powTen;
        unsigned char  i;
        unsigned char  digit;
    
        for (i = 0; i != DIM(PowTenTbl); i++)
        {
            digit  = 0;
            powTen = PowTenTbl[i];
    
            while (bin >= powTen)
            {
                bin -= powTen;
                digit++;
            }
    
            display(digit + '0');
        }
    }
    
    {
        ...
        BinToDec(arr[2])
    }

Reply
  • void BinToDec(unsigned char)
    {
        unsigned char  powTen;
        unsigned char  i;
        unsigned char  digit;
    
        for (i = 0; i != DIM(PowTenTbl); i++)
        {
            digit  = 0;
            powTen = PowTenTbl[i];
    
            while (bin >= powTen)
            {
                bin -= powTen;
                digit++;
            }
    
            display(digit + '0');
        }
    }
    
    {
        ...
        BinToDec(arr[2])
    }

Children