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


Please Help Members By Posting Answers For Below Questions

Difference between strcpy() and memcpy() function?

673


Explain argument and its types.

596


What is the translation phases used in c language?

628


Explain low-order bytes.

619


What is floating point constants?

685






What are the features of c language?

617


Are there namespaces in c?

564


What is clrscr in c?

668


how many errors in c explain deply

1625


Explain about C function prototype?

601


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

1477


What is a built-in function in C?

786


How can I do graphics in c?

586


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1467


Which is better oop or procedural?

627