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
Is c still used?
What is function pointer c?
is it possible to create your own header files?
How can type-insensitive macros be created?
How can you call a function, given its name as a string?
What does int main () mean?
What are the properties of union in c?
Explain the use of function toupper() with and example code?
how to execute a program using if else condition and the output should enter number and the number is odd only...
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.
What is the difference between struct and typedef struct in c?
Difference between macros and inline functions? Can a function be forced as inline?
What are qualifiers in c?
Can we use any name in place of argv and argc as command line arguments?
What is main () in c?