# Help understanding hex?

#1

I just can’t seem to understand hex. I understand that it counts: 1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11. I understand that 10 in hexadecimal is 16 in decimal format.

How in the world does 0x3c (or simply 3c) translate to 60?

Any help would be appreciated. Thank you.

#2

It is pretty straightforward once you remember some basic facts relating to representation of numbers in different bases (radixes.)

Some definitons, first:
S[color=#FF0000] := [/color]D means S is defined as D;
R^N == R * R * R … * R (R multiplied by itself N times)
R^0 == 1 (because R^0 = R/R = R^1*R^-1 = R^(1-1))

In the decimal number system, with base 10 (R=10), we use the ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to write our numbers in base-10 notation.

Take the decimal number 12357 as an example; it has five digits (D=5)
12357 (in decimal) [color=#FF0000]:=[/color] 1 * 10^4 + 2 * 10^3 + 3 * 10^2 + 5 * 10^1 + 7 * 10^0 (in decimal)

In binary number system, with base 2 (R=2), we use only the symbols 0 & 1 to write our numbers in base-2 notation.

Now, take the binary number 110011 as an example; it has six digits (D=6).
110011 (in base-2) [color=#FF0000]:=[/color] 1 * 2^5 + 1 * 2^4 + 0 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 (in decimal)

In the hexadecimal number system, with base 16 (R=16), we have the sixteen symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F to write our numbers in base-16 (hex) notation (with t(0) = 0, t(1) = 1, …, t(A)=10, t(B)=11, …, t(F)=15; where t is a function that translates a symbol in the base-16 system to a number in the decimal system.)

Now, consider the hexadecimal number FF0123AB as an example; it has eight digits (D=8):
FF0123AB (in hex) [color=#FF0000]:=[/color] t(F) * 16^7 + t(F) * 16^6 + t(0) * 16 ^ 5 + t(1) * 16 ^ 4 + t(2) * 16^3 + t(3) * 16^2 + t(A) * 16^1 + t(B) * 16^0 (in decimal)
Replacing each f(.) above with the the corresponding number we get:
FF0123AB (in hex) [color=#FF0000]:=[/color] 15 * 16^7 + 15 * 16^6 + 0 * 16 ^ 5 + 1 * 16 ^ 4 + 2 * 16^3 + 3 * 16^2 + 10 * 16^1 + 11 * 16^0 (in decimal)

To generalize, consider the base-R number system; we use the R symbols s0, s1, s2, …, s (R-2), s(R-1) to write our numbers in this base (assuming t (s0) = 0, t (s1) = 1, t (s2) = 2, …, t (s(R-2)) = (R-2), t (s(R-1)) = (R-1); where t is a function that translates a symbol in the base-R system to a number in the decimal system.)

Now consider a number in this base: zxy … cba, with 26 digits (N=26) (where each digit is one of the R symbols s0, s1, s2, …, s (R-2), s(R-1))
Then zxy … cba (in base-R) [color=#FF0000]:=[/color] t(z) * R^(N-1) + t (x) * R^(N-2) + t(y) * R^(N-3) + … + t© * T^2 + t(b) * R^1 + t(a) * R^0 (in decimal)
(Replace each f(.) above with the the corresponding number to get the concrete answer.)

You know what, here a is challenge for you: write a program that converts numbers represented in one base to corresponding numbers in another base (hint: use the decimal number system as the intermediate system.)

#3

Ok, now that making a lot more sense. To solve my previous problem, it would be as simple as:

0x3c = 316^1 + 1216^0
0x3c = 48 + 12
0x3c = 60

Thank you for your help. I’m going to play around with this a little bit and I’ll post the code I come up with afterwards. Thanks again!

#4

[quote=“itsmewade”]Ok, now that making a lot more sense. To solve my previous problem, it would be as simple as:

0x3c = 316^1 + 1216^0
0x3c = 48 + 12
0x3c = 60

Thank you for your help. I’m going to play around with this a little bit and I’ll post the code I come up with afterwards. Thanks again![/quote]

Took me a little while to understand this - but I know do.

Thanks for typing out the formula.