Public Group

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.

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)

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633344
• Total Posts
3011438
• Who's Online (See full list)

There are no registered users currently online

×