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

What is maximum size of array in c?

1048


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

1088


Whats s or c mean?

1035


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

1211


Explain what is the purpose of "extern" keyword in a function declaration?

1079


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

1096


Can we compile a program without main() function?

1133


How can I determine whether a machines byte order is big-endian or little-endian?

1067


What’s the special use of UNIONS?

1155


What is a null string in c?

1052


Can a variable be both const and volatile?

1139


Explain which function in c can be used to append a string to another string?

1096


What is difference between static and global variable in c?

1066


write a c program to calculate sum of digits till it reduces to a single digit using recursion

3319


Which driver is a pure java driver

1632