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 / 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

Why we write conio h in c?

1038


The file stdio.h, what does it contain?

1166


What is the Purpose of 'extern' keyword in a function declaration?

1084


What is linear search?

1138


Difference between exit() and _exit() function?

1139


List the variables are used for writing doubly linked list program.

2036


Explain how to reverse singly link list.

1147


What is string constants?

1149


How can I do serial ("comm") port I/O?

1184


Explain the bubble sort algorithm.

1075


Explain the advantages and disadvantages of macros.

1105


What is assignment operator?

1059


How to delete a node from linked list w/o using collectons?

2782


What is default value of global variable in c?

994


How many main () function we can have in a project?

1115