MathExchange,

I am trying to learn more about computers, and one thing I have opted to teach myself is decimal to binary, and decimal to hex conversion.

From the web, I have found tutorials on converting small numbers (e.x. 256) to hex. The general rule of thumb is to keep dividing by 16, and remember all of the remainders. Finally, the remainders correspond with numbers or letters on a chart.

But what about big numbers, and negative numbers? I can't seem to find anything on these.

Could one of you really smart people help me figure out these two examples:

1) 123,456,789
2) -44

If I can figure out the process for converting those to hex, I should be happy with this weekend's learning :)

• Use exactly the same rules for large and negative. Just ignore the sign, convert to hex and then add the sign back in. – Mufasa Jan 11 '15 at 22:33

The algorithm will always be the same. Note two things:

1. in notation the sign will always be kept, i.e. $-16_{10} = -10_{16}, -15_{10} = -\text F_{16}$ (base subscripted)
2. computers work differently: they store the sign by letting the first stored bit to equal $-2^k$ where $k$ is the bit-length of the data structure such that $\text{FF} = -1$ while $00\text{FF} = 255$. The rule of thumb here is that an all-$\text F$-data is always equal to $-1$.

For big numbers, you try to find the largest power of $16$ that is still smaller than your number, and see how many times that one divides your number. Then you proceed with the second largest power, and so on. For negative numbers, you can calculate the hexadecimal of the absolute value of the number, and then stick a minus sign in front of it.

To convert 123,456,789, in base 10, to base 16, divide by 16. 16 divides into 123,456,789 7716049 times with remainder 5. 16 divides into 7716049 482253 times with remainder 1. 16 divides into 482253 3140 times with remainder 13 (which we would write "C" in hexadecimal). 16 divides into 3140 83 times with remainder 12 (which we would write "B" in hexadecimal). Finally, 16 divides into 83 5 times with remainder 3.

123,456,789, in base 10, is 53BC15 in base 16.

To see why that works observe that the fact that "16 divides into 123,456,789 7716049 times with remainder 5" means that 123,456,789= (771049)(16)+ 5. The fact that "16 divides into 7716049 482253 times with remainder 1" means that 7716049= (482253)(16)+ 1 so that 123,456,789= ((482253)(16)+ 1)(16)+ 5= (442253)16^2+ 16+ 5. The fact that "16 divides into 482253 3140 times with remainder 13" means that 492253= (3140)16+ 13 so that 123,456,789= ((3140)16+ 13)16^2+ 16+ 5= (3140)16^3+ (13)(16^2)+ 16+ 5. The fact that "16 divides into 3140 83 times with remainder 12" means that 3140= (83)16+ 12 so that 123,456,789= ((83)16+ 12)16^3+ (13)16^2+ 16+ 5= (83)16^4+ (12)16^3+ (13)16^2+ 16+ 5. The fact that "16 divides into 83 5 times with remainder 3" means that 83= (5)16+ 3 so 123,456,789= ((5)16+ 3)16^4+ (12)16^3+ (13)16^2+ 16+ 5= (5)16^5+ (3)16^4+ (12)16^3+ (13)16^2+ 16+ 5 which is just 53BC15 in base 16.

• $482253 / 16 = 3\color{red}{0}140$ with remainder $13$. Also, the hexadecimal code for $13$ is $D$ instead of $C$. Finally, the end result is $75BCD15$ instead of $53BC15$. – achille hui Sep 27 '15 at 6:52