Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write code for atoi(x) where x is hexadecimal string.

Answer Posted / mohammed sardar

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 ?    10 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What functions are used for dynamic memory allocation in c language?

1153


What is difference between static and global variable in c?

1058


regarding pointers concept

2040


What is dynamic memory allocation?

1338


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

2079


What does typedef struct mean?

1114


What is function prototype in c language?

1034


Is struct oop?

1010


How to get string length of given string in c?

1067


Why is it important to memset a variable, immediately after allocating memory to it ?

2077


What are the standard predefined macros?

1146


What is volatile, register definition in C

1109


What is wrong with this statement? Myname = 'robin';

1327


What is property type c?

1092


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

2096