Jump to content
Tuts 4 You
Sign in to follow this  
deepzero

(c++) int 2 hex (simple way?)

Rate this topic

Recommended Posts

deepzero

Hi,

i have a decimal number in an int variable, which i want to convert to hex and save in a DWORD, ie:

int a = 4660;

-> ==

DWORD b = 1234;

I was not able to find a simple way to do this conversion.

It works via strtol or sprintf, but there has to be an easier way?

After all, the int variable is stored in hex in memory... :verymad:

deep :)

Edited by deepzero (see edit history)

Share this post


Link to post
Share on other sites
baguette

b = a;

your question doesn't really make sense.

Share this post


Link to post
Share on other sites
deepzero
b = a;

sure, this is just about the conversion... :)

if i have "int a = 4660", how can i convert it into a "dword b = 1234;" ?

Whilst it is possible using strtol:
/>http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

or sprintf
/>http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

i was wondering whether there is a simpler way, because the int is stored hexadecimal in memory already.

:)

Share this post


Link to post
Share on other sites
Aguila

do you even know what hexadecimal and decimal is? I guess you don't, use wikipedia. The thing you want to do is silly.

Share this post


Link to post
Share on other sites
deepzero

Hi,

Oh, i do know what hex/dec is. :)

I discussed this with metr0 in icq, and while presenting my problem i noticed....that there actually is no problem and everything works fine. :thumbsup:

He called that the "Demonstration Paradox" :teehee:

anyways, thanks to everyone involved & have a nice evening,

deep0 :)

Share this post


Link to post
Share on other sites
GaBoR

Everything is stored in binary, you know 0's and 1's, hexadecimal is just a representation.

Share this post


Link to post
Share on other sites
Syntax

Guys , Don't to be such a smartass before understanding his question .

Share this post


Link to post
Share on other sites
Killboy

The question itself was dumb, what's there to understand?

Even if it wasn't, if someone can't explain his problem properly, how does telling him so make anyone a smartass?

I can't even see anyone yelling "newb pow roflol"

// Hm. Did I just fall for the troll :unsure:

Share this post


Link to post
Share on other sites
Syntax

Yes , You just fall for the troll :rolleyes:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...