By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

How to convert hexadecimal to decimal integer?

P: 24
How to convert an hexadecimal integer to decimal integer? Is there a function to do that in VC++?
Mar 9 '11 #1
Share this Question
Share on Google+
6 Replies


100+
P: 542
Yes 'dec' will change the format from hexi-decimal to decimal
Mar 10 '11 #2

Banfa
Expert Mod 5K+
P: 8,916
There is not such thing as a hexadecimal integer or decimal integer. All integer types are binary.

There is such a thing as a string containing character data that equates to a decimal integer or hexadecimal integer. You can use strtoul or strtol to convert strings of digits in any base to a long or unsigned long type.
Mar 10 '11 #3

P: 24
which library I can use for the function dec ?
Mar 10 '11 #4

100+
P: 542
'hex', 'dec' and 'oct' are not functions...I believe they are known as i/o manipulators e.g.
Expand|Select|Wrap|Line Numbers
  1. std::cout<<"enter a hexadecimal numeral":
  2. std::cin>>hex>>n;//if 511 is entered for n
  3. std::cout<<hex<<n;//prints 1ff
  4. std::cout<<dec<<n;//prints 511
Have assumed they are defined in <iostream>
Mar 13 '11 #5

Banfa
Expert Mod 5K+
P: 8,916
No the io manipulators are defined in <iomanip> and strictly speaking io manipulators are functions you just don't use a function like syntax to call them.
Mar 14 '11 #6

100+
P: 542
Stroustrup`s Programming says "The standard manipulators are defined in <ios>, <istream>, <ostream>, <iostream>, and <iomanip> (for manipulators that take arguements):" pp1129
....but(Banfa)your post raised my interest.
Mar 15 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.