Solved

Change Format to hex

Posted on 2013-05-11
5
339 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 83

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 83

Accepted Solution

by:
Dave Baldwin earned 500 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 83

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Should CArray be used for a list of pointers in C++? 19 144
White board coding practice 3 98
Unable to start eclipse ? 17 174
Resolve Dependency Issues 4 98
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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 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.

739 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