question about hex code

ShawnDarichuk

Banned
Jul 9, 2002
19
0
0
i'm only familar with 2 digit hex numbers such as EF or FF and values like that.

i'm wondering how to make numbers larger than 255(256 human terms) in hex code. does it work by multiplying combinations of 2 digits?
example: 0EFF = (1 x 15) x (16 x 16)
or does it work by multiplying just multiplying the values which will make the number
example: EFF = 15 x 16 x 16

another question. how do you figure out which numbers to multiply in order to make that number? is it any different if i use different hex values to get at the same end value? let me give examples
34 = 3 x 4 = 12
26 = 2 x 6 = 12
are 34 and 26 completely interchangable?

thank you in advance :)
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Here's a simple formula that works with *any* base, including base 16.

n=v*r^p

Where v is the value, r is the radix (base), and p is the position in the number. The result is n which can be added for every position in the number (i.e. the number's "width"). e.g.

EA13

Using the above formula, this would expand to...

n = (14*16^3) + (10*16^2) + (1*16^1) + (3*16^0)

or...

59921 = 57344 + 2560 + 16 + 1

Remember, when evaluting numeric expressions in terms of their radix, the right-most number starts at position 0, and anything to the power of 0 is 1. Lets apply the same formula to a ternary expression...

123

n = (1*3^2) + (2*3^1) + (3*3^0)

or...

18 = 9 + 6 + 3

The whole point of this is to make you think not in terms of hexadecimal, or ternary, of binary, but to make you think in terms of each numerber system's radix and to apply the same formula. Other helpful formulas are...

To get the total number of possible values for a given number's "width" (how many numbers)

v=r^w. An example for a byte in terms of binary would be...

256=2^8

You can see there are 256 total possible numbers for a given byte, 8 bits. Now, to see the maximum value possible for a given number's "width"...

v=r^(w - 1)

or, using the sample above...

255=2^(8-1)

There are 256 total possible numbers in a byte, but 255 is the maximum value, in decimal, that can be represented by 8 bits.

Hope that wasn't a completley worthless discussion for you...
 

KillerCow

Member
Jun 25, 2001
142
0
0
You seem to be a little confused as to what hex represents. It is a base16 number system, instead of our base10 system.

In Decimal (our standard system) there are 10 characters, so each digit in a number represents a power of 10.
i.e.
1234 (base10) = (4 * 10 ^ 0) + (3 * 10 ^ 1) + (2 * 10 ^ 2) + (1 * 10 ^ 3) = 1234 (base10)

in hex there are 16 characters, so each digit in a number represents a power of 16.
A (base16) = 10 (base10)
B (base16) = 11 (base10)
C (base16) = 12 (base10)
D (base16) = 13 (base10)
E (base16) = 14 (base10)
F (base16) = 15 (base10)
i.e.
1234 (base16) = (4 * 16 ^ 0) + (3 * 16 ^ 1) + (2 * 16 ^ 2) + (1 * 16 ^ 3) = 4660 (base10)
EF (base 16) = (15 * 16 ^ 0) + (14 * 16 ^ 1) = 239 (base10)

The previous reply is good from going from base(x) to DEC.
To convert from DEC to HEX you want to find out how many times the number can be divided by the largest porwer of 16 that is less than the number, then use the reaminder to find the next digit.

So 520 (base10) / 256 = 2, remainder=8
8 / 16 = 0, remainder = 8
8 / 1 = 8, remainder=0
So 520 (base10) = (8 * 16 ^ 0) + (0 * 16 ^ 1) + (2 * 16 ^ 2) = 208 (base16)

Go to MathWorld (am I a geek or what?) for more info on bases and math in general.

Or you could just use windows calculator to do your conversions. Just put it in scientific mode and use the radio buttons on the left.