• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Change Format to hex

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
Spad3z
Asked:
Spad3z
  • 3
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
The number 123456 is Not the same as 0x123456.  Try it in your calculator.  0x123456 = 1193046 decimal.
0
 
Spad3zAuthor Commented:
@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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Spad3zAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now