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

Is c still used?

598


What is function pointer c?

584


is it possible to create your own header files?

631


How can type-insensitive macros be created?

692


How can you call a function, given its name as a string?

710






What does int main () mean?

544


What are the properties of union in c?

584


Explain the use of function toupper() with and example code?

651


how to execute a program using if else condition and the output should enter number and the number is odd only...

1652


The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.

1626


What is the difference between struct and typedef struct in c?

652


Difference between macros and inline functions? Can a function be forced as inline?

706


What are qualifiers in c?

572


Can we use any name in place of argv and argc as command line arguments?

606


What is main () in c?

584