• ### What is your GameDev Story?

Public Group

#### Archived

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

# hex question

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

## 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 on other sites
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!!

##### 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 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!!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634112
• Total Posts
3015580
×