unsigned int get_number(char c)
{
if(c > 47)
return (unsigned int)(c-48);
else
return 0;
}
Decimal Octal Hex Binary Value
------- ----- --- ------ -----
[B]048[/B] 060 030 00110000 0
[B]049[/B] 061 031 00110001 1
[B]050[/B] 062 032 00110010 2
[B]051[/B] 063 033 00110011 3
[B]052[/B] 064 034 00110100 4
[B]053[/B] 065 035 00110101 5
[B]054[/B] 066 036 00110110 6
[B]055[/B] 067 037 00110111 7
[B]056[/B] 070 038 00111000 8
[B]057[/B] 071 039 00111001 9
Code C - [expand] 1 2 3 4 5 6 7 char x; unsigned int y; x='0'; // x holds char 0 which is value 48 x=x-48; // x becomes 0 y= (unsigned int)x-48; //or use typecasting
what is the problem of the code?
How do you check the entered value, because there are also * / A B C D what happens if these are pressed or for value 8A or 9A.
Alex
Code C - [expand] 1 2 3 4 5 6 7 t = (unsigned int)(deg[0]); t = (t-48)*10; u = (unsigned int)(deg[1]); u = (u-48); k = t+u; if (k < 91) {}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 if ((deg[0]>47) & (deg[0]<58) & (deg[1]>47) & (deg[1]<58)){ // check that both chars contain numbers (0-9) and not A,B,C etc t = (unsigned int)(deg[0]); t = (t-48)*10; u = (unsigned int)(deg[1]); u = (u-48); k = t+u; if (k < 91) {} }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 void main(void){ volatile unsigned char deg[2]; volatile unsigned int t, u, k; deg[0]='8'; deg[1]='9'; t = (unsigned int)(deg[0]); t = (t-48)*10; u = (unsigned int)(deg[1]); u = (u-48); k = t+u; if (k < 91) {} while(1); }
lets try an easy way.......and the best way....ascii is xxxx yyyy....where x is ur ascii identifier and yyyy is ur number........take input and take anl with 00001111.....it will leave ur number back!....or keyboard it works wont be needing 48s....or u can use datapointers DPTR.......ur choise
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?