Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change Format to hex

Posted on 2013-05-11
5
Medium Priority
?
345 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 84

Expert Comment

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

Author Comment

by:Spad3z
ID: 39158784
@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 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 39158881
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
ID: 39160063
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 84

Expert Comment

by:Dave Baldwin
ID: 39160270
You're welcome, thanks for the points.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

927 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