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
What is array of structure in c programming?
Explain what are run-time errors?
What is difference between static and global variable in c?
Are local variables initialized to zero by default in c?
plz let me know how to become a telecom protocol tester. thank you.
in iso what are the common technological language?
What does %p mean c?
Why is c called "mother" language?
c program to compute AREA under integral
What is %s and %d in c?
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.
What is a macro?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
write a c program to find the sum of five entered numbers using an array named number
What is the benefit of using const for declaring constants?