#9641 - IAMTHEEVILBEAN - Tue Aug 12, 2003 12:26 am
hmmmm i am learning C++ and i cant figure out these hex digits....does anyone know them and cangive me a few hints....plz?
_________________
Moose
#9643 - DekuTree64 - Tue Aug 12, 2003 1:34 am
It's just like regular decimal numbers except instead of each digit being 0-9, or 10 possibilities, you have 16 possibilities. So the first digit is 0-15, but since we don't have numbers for 10-15, we use the first 6 leffers of the alphabet, a-f. Then instead of each space to the left multiplying by 10 (take 10 itself for example, it's 1 * ten, or 1 shifted one space to the left), each space multiplies by 16, so 10 in hex is 16 in decimal. Then if you separate the digits up, take 42 for example, would be 4 * 10 + 2. Then for hex, say 2A, you'd have 2 * 16 + 10 (because A comes after 9 in hex). Then one more space to the left multiplies by 16 again, so 123 in hex would be 1 * 16 * 16 + 2 * 16 + 3, or 256 + 32 + 3, which is 291. So to convert a hex number to regular decimal you have to separate it into digits, multiply by 16 for each space over, and add them together.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#9644 - IAMTHEEVILBEAN - Tue Aug 12, 2003 1:49 am
WOW ill wrok on that and try it out thnx alot man....i can finally mov on
_________________
Moose
#9651 - Sweex - Tue Aug 12, 2003 9:16 am
Hex numbers are used in code using the prefix 0x. So if you want to use a hexadecimal number in code (often for readability), write it like this: 0xff, 0xabcd, 0xBE...
You can also display numbers as hexadecimal with printf(-like) functions. Use %x to do so.
_________________
If everything fails, read the manual: If even that fails, post on forum!
#9653 - niltsair - Tue Aug 12, 2003 2:18 pm
They're convenient because a 2 digits hex value represent a 8bits variable.
0xFF -> maximum value of a 8bits value (0x is just a prefix to tell it's a hex number)
So each digit represent 4bits.
0xF0 = [1111] [0000]
#9655 - mtg101 - Tue Aug 12, 2003 4:10 pm
It's worth noting that most calculator apps, even the built in windoze one, handle hex/dec/oct/bin modes - which is very handy for quickly converting between different bases.
Oh yeah - and if you get a calculator that can do base-13, you can proove that the answer to "What is six multiplied by nine?" is indeed 42. :)
_________________
---
Speaker for the Dead