Write code for atoi(x) where x is hexadecimal string.

Answer Posted / john huang

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]>='a') && (x[n-1]<='f'))
sum+=(x[n-1]-'a'+10)<<leftshift;
n--;
leftshift+=4;
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is array of structure in c programming?

759


Explain what are run-time errors?

614


What is difference between static and global variable in c?

541


Are local variables initialized to zero by default in c?

557


plz let me know how to become a telecom protocol tester. thank you.

1745






in iso what are the common technological language?

1639


What does %p mean c?

634


Why is c called "mother" language?

862


c program to compute AREA under integral

1818


What is %s and %d in c?

596


stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

1858


What is a macro?

661


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1256


write a c program to find the sum of five entered numbers using an array named number

1622


What is the benefit of using const for declaring constants?

592