Solved

Change Format to hex

Posted on 2013-05-11
5
328 Views
Last Modified: 2013-05-12
Hello experts,

My question that I've been stuck on for a while is how can i add "0x" in front of a number without changing the actual number itself.

In VC++ using namespace System It can be done like so..
int Number = 123456;
txtNumber->Text = Number.ToString("X8")

Open in new window

txtNumber->Text will show "0x123456".

But i want to do that exact thing without using the namspace System, and System::String.

and one more thing instead of having the number displayed into "txtNumber->Text" I'd rather have it be put back into "int Number". So each time i use "Number" it'll equal "0x123456".

Thanks for your help.
0
Comment
Question by:Spad3z
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
The number 123456 is Not the same as 0x123456.  Try it in your calculator.  0x123456 = 1193046 decimal.
0
 

Author Comment

by:Spad3z
Comment Utility
@DaveBaldwin - Yes I'm aware of that, I merely just want to add "0x" infront of any number. or if this makes things easier. Make 1193046 into 0x123456 within "int Number".
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
That isn't going to do what you think.  The '0x' is just a display method, not a change in the number.  Normally you would just use 'printf' with the 'x' specifier to get the number to display in hex instead of decimal.  http://msdn.microsoft.com/en-us/library/wc7014hz%28v=vs.71%29.aspx
0
 

Author Comment

by:Spad3z
Comment Utility
No solution found, as DaveBaldwin said does not work like that. I've found a way around my issue. Thank you for your time.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome, thanks for the points.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

772 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

11 Experts available now in Live!

Get 1:1 Help Now