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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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
 
Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list? Oracle1
What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack  5
write a program to print sum of each row of a 2D array.  2
how to generate sparse matrix in c  1
why java is called as a purely oops language.  2
What are advantages and disadvantages of recursive calling ? HP11
give one ip, find out which contry Google4
what is difference between array of characters and string Accenture10
main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Find the Outputs? CitiGroup7
void main() { int s[4][2]={ {1234,56},{1212,33},{1434,80},{1312,78} }; int (*p)[2]; int i,j,*pint; for(i=0;i<=3;i++) { p=&s[i]; pint=p; printf("\n"); for(j=0;j<=1;j++) printf("%d",*(pint+j)); } } while running this program it shows a warning-suspicious pointer conversion ie pint=p; my que is why should we assign the value of p to pint again.why cant we use it directly as *(p+j)..but if i use like tat the o/p is garbage value..  1
which will be first in c compiling ,linking or compiling ,debugging. Sonata3
If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.  4
what does " calloc" do? Cadence6
What compilation do? Geometric-Software7
can anyone proide me reading material on svit00ef27@yahoo.com please thanx in advance IBM1
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview Satyam2
How many types of linked lists what are they? How many types of data structures?  4
write a addition of two no. program with out using printf,scanf,puts .  3
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE? Wipro1
code for copying two strings with out strcpy() function.  5
 
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