Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert hexadecimal to decimal

Posted on 2002-04-19
2
1,318 Views
Last Modified: 2008-01-09
Is there a function in c library to convert a hex to decimal? For example, if there is a hex number hex=01020304, how to convert it to be decimal number?
0
Comment
Question by:czz
2 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 50 total points
ID: 6955330
Is strtol what you are looking for?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6957453
strtol (string to long) or strtoul (string to unsigned long) will do the job, as GGrundy says.  Be sure to set the last parameter to 16 so that it will know you are converting hexidecimal digits.  For instance:

char* pEnd;
char szHexText="0102A53F";

unsigned long nBinaryValue= strtoul( szHexText, &pEnd, 16 );

-- Dan
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question