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
How can you be sure that a program follows the ANSI C standard?
What is the role of && operator in a program code?
Write a factorial program using C.
Differentiate between a for loop and a while loop? What are it uses?
What is the function of this pointer?
Explain two-dimensional array.
Why is c not oop?
What are the advantages and disadvantages of pointers?
In a switch statement, explain what will happen if a break statement is omitted?
Write a C program linear.c that creates a sequence of
processes with a given length. By
sequence it is meant that each created process has exactly
one child.
Let's look at some example outputs for the program.
Here the entire process sequence consists of process 18181:
Sara@dell:~/OSSS$ ./linear 1
Creating process sequence of length 1.
18181 begins the sequence.
An example for a sequence of length three:
Sara@dell:~/OSSS$ ./linear 3
Creating process sequence of length 3.
18233 begins the sequence.
18234 is child of 18233
18235 is child of 18234
........ this is coad .... BUt i could not compleate it .....:(
#include
Can the size of an array be declared at runtime?
What does double pointer mean in c?
What is the purpose of macro in C language?
Who developed c language?
What should malloc() do?