• 12-30-2008
sharkbate24
Hi Everyone,

I am really confused about hexadecimal numbers, and I feel it's holding me back from continuing to learn C++.

So, in C++ For Dummies, it says this:

Quote:

123 to the power of 10, becomes 7B to the power of 16.
I really don't understand how 7B to the power of 16 appears as 123 to the computer.

Any idea's?

Many thanks.
• 12-30-2008
laserlight
Quote:

Originally Posted by sharkbate24
I am really confused about hexadecimal numbers, and I feel it's holding me back from continuing to learn C++.

Well, there are many areas of C++ that have nothing or little to do with hexadecimal numbers, so you really should not feel that way :)

Quote:

Originally Posted by sharkbate24
I really don't understand how 7B to the power of 16 appears as 123 to the computer.

It arguably appears as neither 7B nor 123 to the computer, but as a number in binary representation.

7B in base 16 = 7 * 16 + 11 = 123 in base 10
• 12-30-2008
sharkbate24
Quote:

Originally Posted by laserlight
Well, there are many areas of C++ that have nothing or little to do with hexadecimal numbers, so you really should not feel that way :)

It arguably appears as neither 7B nor 123 to the computer, but as a number in binary representation.

7B in base 16 = 7 * 16 + 11 = 123 in base 10

Wow, you're clever hehe. I would never be able to work that out.

Thanks :D.
• 12-30-2008
brewbuck
If you understand decimal then you understand hexadecimal.

In decimal we have the one's place, the ten's place, the hundred's place, etc.

In hex we have the one's place, the sixteen's place, the 256's place, etc.

In decimal, each "place" is bigger by a factor of ten. In hex, by a factor of sixteen.

The problem is we only have ten Arabic numerals, but we have to represent sixteen digits, so we use the six letters A, B, C, D, E, F for the excess.

Given this, does Laserlight's calculation make any more sense?

7B -- in the one's place there is a 'B', which is eleven. In the sixteen's place is a 7. So you have seven sixteens, which is 112. Plus another eleven, which is 123.
• 12-30-2008
sharkbate24
Quote:

Originally Posted by brewbuck
If you understand decimal then you understand hexadecimal.

In decimal we have the one's place, the ten's place, the hundred's place, etc.

In hex we have the one's place, the sixteen's place, the 256's place, etc.

In decimal, each "place" is bigger by a factor of ten. In hex, by a factor of sixteen.

The problem is we only have ten Arabic numerals, but we have to represent sixteen digits, so we use the six letters A, B, C, D, E, F for the excess.

Given this, does Laserlight's calculation make any more sense?

7B -- in the one's place there is a 'B', which is eleven. In the sixteen's place is a 7. So you have seven sixteens, which is 112. Plus another eleven, which is 123.

Aah, that's really cleared things up, thanks a lot.

But I don't quite understand how we know if it's an Hexadecimal Number, or another one, such as Octadecimal number?

Thanks a lot.
• 12-30-2008
ZuK
Quote:

Originally Posted by sharkbate24
But I don't quite understand how we know if it's an Hexadecimal Number, or another one,

If the number is an integer literal appearing in c or c++ code we know.
if it starts with 0x it's hex, if it starts with 0 it's octal anything else is decimal.
Kurt
• 12-30-2008
EVOEx
Quote:

Originally Posted by sharkbate24
Aah, that's really cleared things up, thanks a lot.

But I don't quite understand how we know if it's an Hexadecimal Number, or another one, such as Octadecimal number?

Thanks a lot.

You can't. 10 can have an infinite number of values, depending on it's base. However, we people agreed that base 10 is the usual, so unless otherwise specified, 10 will be just that.. "10". in decimal.
How to indicate depends on who you want to inform the base. If it's a human, you'll just write it down. A compiler will decide on the number itself. Usually, "0x" is prepended to make it a hexadecimal number, while a "0" is prepended to make it octal.
So 010 = 8
0x10 = 16

I've seen it differ sometimes though. Some compilers use "10h" to indicate hex, and a b to indicate binary.