ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
Write code for atoi(x) where x is hexadecimal string.
 Question Submitted By :: Superhuman
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write code for atoi(x) where x is hexadecimal string.
Answer
# 1
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 ?    2 Yes 3 No
Mohammed Sardar
 
  Re: Write code for atoi(x) where x is hexadecimal string.
Answer
# 2
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 ?    1 Yes 0 No
John Huang
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
WAP to convert text into its ASCII Code and also write a function to decode the text given?  2
What is meant by global static? why we have to use static variable instead of Global variable L&T2
what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }  7
plz answer.... write a program that reads line (using getline) e.g."345", converts each line to an integer using "atoi" and computes the average of all the numbers read. also compute the standard deviation.  1
what is data structure  4
what will be the output: main(){char ch;int a=10;printf("%d",ch);} Wipro29
main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } CitiGroup15
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a  3
two variables are added answer is stored on not for third variable how it is possible?  3
How to add two numbers with using function?  3
can anyone proide me reading material on svit00ef27@yahoo.com please thanx in advance IBM1
Result of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error IBM4
compute the nth mumber in the fibonacci sequence? TCS7
Is it possible to create recycle bin in mobiles?  2
what is available in C language but not in C++?  1
Which command is more efficient? *(ptr+1) or ptr[1]  3
write a c program to check weather a particluar bit is set or not? IBM4
C program to perform stack operation using singly linked list  1
What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access? Excel1
write a C code to reverse a string using a recursive function, without swapping or using an extra memory. Motorola2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com