Solved

Hexadecimal String to uint64_t

Posted on 2011-03-11
3
1,909 Views
Last Modified: 2012-05-11
Hey guys,

How can I convert this?

std::string macAddress = "0x0493934FF3";

into a uint64_t?  I know atoi can pack a hex string into a 32-bit integer but I have no idea how to get it into a 64-bit integer which is how our system stores MAC addresses.  I need this ability to read the XML strings from our configuration into the system.

Thanks!

-w00te
0
Comment
Question by:w00te
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Zoppo earned 400 total points
Comment Utility
Hi w00te,

you could use a stringstream, i.e. like this:
	__int64 n;
	std::stringstream ss;
	ss.str( macAddress );
	ss >> std::hex >> n;
	// check it
	std::cout << std::hex << n << std::endl;

Open in new window


Hope that helps,

ZOPPO
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
ah - sorry, forgot to say you need to

#include <sstream>

Open in new window

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
Comment Utility
Just for the sake of completeness - there's also '_strtoui64()': http://msdn.microsoft.com/en-us/library/85zk715d%28VS.80%29.aspx (scroll down for the example)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now