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 do you mean by command line argument?
What is sizeof in c?
What are the different types of data structures in c?
How are 16- and 32-bit numbers stored?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
What is exit() function?
Where static variables are stored in memory in c?
Does c have enums?
What happens if you free a pointer twice?
Is a house a shell structure?
What is a program flowchart?
design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.
What is an expression?
Can one function call another?
How does sizeof know array size?