Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kordova

hex question

This topic is 5646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m playing around with binary, octal, hex and decimal numbers in c right now and had two questions. Is there a "0x" or "h" equivalent for a binary value being assigned to an integer? ex. int x = 0x20, y = 101b; ? Also, if I have an integer of any given value how can I assign that in another system to another variable ex. int dec = 10, hex=0xdec; ?

Share this post


Link to post
Share on other sites
Advertisement
1. There is no way to set a variable by writing it in straight binary in C or C++.

2. I also am not sure if I understand your question. Do you want it to display as hex/dec/oct or do you mean you want to convert it from one base to another logically?

If this code:
int dec = 10, hex = 0xdec;

is supposed to set dec to 10 and hex to 0xA then you can just write instead:

int dec = 10, hex = dec;

because logically they are the same.



The hackers must have gotten into the system through the hyperlink!!
Invader''s Realm

Share this post


Link to post
Share on other sites
Ok, thanks.

About the second, I meant assign the hex value in decimal format to hex. (If dec was 20 then hex would equal 32)? Thanks ahead.

Share this post


Link to post
Share on other sites
You mean that if dec is 10 you want hex to be ''A'' and not 0xA? If so, then hex needs to be a string and not an int because 10 means the same thing in every base and is stored the same way on your computer no matter if it is 10, 0xA, or whatever. To assign hex the string representation of dec you''ll have to either write your own conversion function, use stringstreams (C++), or something else.



The hackers must have gotten into the system through the hyperlink!!
Invader''s Realm

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!