Public Group

# What are Hex values used for in C++?

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

## Recommended Posts

What are Hex values used for in C++ like when someone shows this 0x0F1 or something similar? because it shows in my book this function starts from character 0x blady bla can't remember lol then goes to something else. Are Hex values nessecary?

##### Share on other sites
Hex values aren't absolutely necessary but they are so much more convenient.

4,294,967,295 in decimal or 0xFFFFFFFF, take your pick.

Oh and a hex digit is much easier to correlate with a binary number - (ie bits)
15 -> 0xF -> 1111

##### Share on other sites
Quote:
 Original post by GameMasterXLWhat are Hex values used for in C++ like when someone shows this 0x0F1 or something similar? because it shows in my book this function starts from character 0x blady bla can't remember lol then goes to something else. Are Hex values nessecary?

You can certainly use a decimal in your code if you perfer, but hex is quite common. As LessBread pointed out there is a relationship between binary and hex and it can make certain calculations and concepts easier to visualize, such as bitwise operations. Every digit in hex is equal to four bits in binary (aka a nibble and yes that's a technical term). Even if you don't use it yourself it's probably a good idea to get comfortable with it.
Hex is just base 16 or every position is 16 raise to a power, starting from 0 and from right to left. A thru F represent the digits 10 thru 15.

...x * 16^3 + x * 16^2 + x * 16^1 + x * 16^0

Were x is a value 0 thru 15(or F)

• ### What is your GameDev Story?

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

• 13
• 10
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634125
• Total Posts
3015668
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!