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
Difference between strcpy() and memcpy() function?
Explain argument and its types.
What is the translation phases used in c language?
Explain low-order bytes.
What is floating point constants?
What are the features of c language?
Are there namespaces in c?
What is clrscr in c?
how many errors in c explain deply
Explain about C function prototype?
i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me
What is a built-in function in C?
How can I do graphics in c?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
Which is better oop or procedural?