Write code for atoi(x) where x is hexadecimal string.
Answer Posted / mohammed sardar
int n=strlen(x) // where x is pointer to hex string
int sum=0;
int leftshift=0;
while(n>0)
{
if((x[n-1]>='0') && (x[n-1]<='9'))
sum+=(x[n-1]-'0')<<leftshift;
if((x[n-1]>='A') && (x[n-1]<='F'))
sum+=(x[n-1]-'A'+10)<<leftshift;
if((x[n-1]>='f') && (x[n-1]<='f'))
sum+=(x[n-1]-'a'+10)<<leftshift;
n--;
leftshift+=4;
}
| Is This Answer Correct ? | 10 Yes | 7 No |
Post New Answer View All Answers
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
What is const keyword in c?
How do you do dynamic memory allocation in C applications?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What is difference between structure and union?
Why do we use null pointer?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell
What is the difference between a free-standing and a hosted environment?
What is the size of enum in bytes?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
Explain what math functions are available for integers? For floating point?
Why we use void main in c?
Explain what does the format %10.2 mean when included in a printf statement?
what do you mean by enumeration constant?