Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change Format to hex

Posted on 2013-05-11
5
Medium Priority
?
343 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

670 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