Jump to content
  • Advertisement
Sign in to follow this  
GameMasterXL

What are Hex values used for in C++?

This topic is 4849 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by GameMasterXL
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?


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)



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!