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
Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given
Explain b+ tree?
which type of aspect you want from the student.
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
What is break statement?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What does %d do?
What is the right type to use for boolean values in c?
What is the use of bit field?
What are the advantages of c preprocessor?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What is operator promotion?
How can I recover the file name given an open stream or file descriptor?
Explain how can type-insensitive macros be created?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)