Converting Base10 to Base16 (Hex)

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
HELP!

I am fine with whole numbers, but I have 273 and I have no clue how to turn that into hex!

Please help :)
 

Beattie

Golden Member
Sep 6, 2001
1,774
0
0
what you have to do is divide the number (273) by 16 and take all each step as a digit in the final number
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0


<< 111 >>



indeed

You use powers of 16...begin with the largest power that will fit...like in this case, 16^2 (256)

so, 273-256=17. U used 16^2 once, so ur number will be 1__ Now 16^1, 17-16=1; (number currently 11_), and lastly 16^0 will finish that last 1...soo, 111

($10 says i cant explain things at all...)
 

tweakmm

Lifer
May 28, 2001
18,436
4
0


<< tweak, 273 is in Base10

i need to get it to Base16, which is hex
>>


well, pepsi answered you, it is 111
I can't explain how to do it now, i have too much homework, but tommorow if nobody tells you how to do it, i will be glad to explain it too you ;)
Good luck

shoot me a PM tonight if you want me to explain it
 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0
easiest way is to convert to binary and then convert to hex or octoal or bas ten whatever,


since hex is base 16 and bin is base 2 it will take 2^4 binary digits to represent one hex digit so when your number is in binary digit block of the numbers in groups of four like this:


1101 1001 0001 1110 (base 2)

13 9 1 14 (base 10)


F 9 1 D (base 16)






if you want to do octal use sets of 3 instead of four.

 

Noriaki

Lifer
Jun 3, 2000
13,640
1
71


<< You use powers of 16...begin with the largest power that will fit...like in this case, 16^2 (256)

so, 273-256=17. U used 16^2 once, so ur number will be 1__ Now 16^1, 17-16=1; (number currently 11_), and lastly 16^0 will finish that last 1...soo, 111
>>

Yeah that's how I do it, work from left to right, you have to work out what the biggest power of 16 that will fit into 273 is first though.
Like he said in this case it's 16^2 so you have a 3 digit number.

So you subtract 16^2 from 273, which subtracts once, leaving 17.
So your leftmost digit is 1

Then you subtract 16^1 from 17, which subtracts once, leaving 1.
So your middle digit is 1 (because it subtracted once)

Then you subtract 16^0 (anything to the 0 is the number 1, but I wrote it 16^0 for form), which subtracts once, leaving 0.
So your right digit is 1.

You have 0 left so you stop.



The other way is to work from right to left, so you don't need to know how many digits you have before you start, but you have to divide.

273/16 = 17 remainder 1
1 is your rightmost digit.

17/16 = 1 remainder 1
1 is your second rightmost digit

1/16 = 0 remainder 1
1 is your third digit from the right

Your quotient was 0 so you stop.


I like the first way better myself, but this way works to, and is probably less work.
I'm not really sure why I like the left to right method better...
Guess cuz my calculator won't do integer division for me :p


 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0
sorry i forgot to do 273 in base 10 is

100010001 in base 2


block off in sets of 4 starting from the right


(000)1 0001 0001 I added the zeros cause we need blocks of 4 its definetly legal (ask if you dont understand why)


so in hex the blocks of 4 would be


1 1 1


or 0h111 (hex)



good luck beast.
 

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
ahhh thanks ameesh, that makes much more sense :)

binary clicks so much better in my brain than hex :)
 

b0mbrman

Lifer
Jun 1, 2001
29,470
1
81
Divide it by the biggest exponent of 16 you can...then divide the remainder by decreasing exponents of 16...

Here, that would be

273/16^2 = 1 r 17
17/16^1 = 1 r 1
1/16^0 = 1 r 0

And there ya go!
 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0


<< ahhh thanks ameesh, that makes much more sense :)

binary clicks so much better in my brain than hex :)
>>





im glad that makes sense
 

Noriaki

Lifer
Jun 3, 2000
13,640
1
71


<< Noriakki, that only works for binary. >>

Mmm..perhaps it does...sorry.
Like I said, I don't use the dividing method.

 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0


<< homework is due tomorrow! and eLiu cant explain worth a damn ;) >>



LoL i told you so ;)

Doing what Ameesh said would be good...though it gets rather annoying when the #s get large (but then again...that's what a calculator is for :D)

I can explain it...i just need to have some paper so i can draw a little diagram thingy that makes things make lotsa sense lol

hmm...maybe ill try again :Q

You know howto go from hex->dec, right?

Like 143 in hex is 323 in decimal.

1______4______3
16^2__16^1___16^0 (plz ignore the underscores...i had to space it out)

256+64+3=323.

(making sense so far?)

Anyway, to go dec->hex, u just reverse the process...begin with as LARGE a power of 16 as you can possibly find.

In the case of 273, 16^2 is obviously the largest power that will go in. And you can only fit 1x of 16^2

So...

1______?______?
16^2__16^1___16^0

Anyway, 273-256=17. Then, you move to 16^1, again, 1x. 17-16=1. And last...16^0. Again, 1x...1-1=0

1______1______1
16^2__16^1___16^0

256+16+1=273

(did that make any more sense than try #1?)

The binary thing works fine, but i like this method better b/c u can use it to convert from base 10 to anything. And...with a little adapting, u can basically use it to convert from any base to any other base (tho going to base 10 first will be easiest)
 

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
eLiu, i would like to tell you that all that work was worth something, but it really wasnt :)

thanks anyways, hehe
 

Noriaki

Lifer
Jun 3, 2000
13,640
1
71


<<

<< Noriakki, that only works for binary. >>

Mmm..perhaps it does...sorry.
Like I said, I don't use the dividing method.
>>



No, I was right.

Try 414
414 / 16 = 25 R 14 (E in Hex)
14 (E) is your rightmost digit.

25 / 16 = 1 R 9
9 is your second digit from the right.

9 / 16 = 0 R 1
1 is your third digit from the right.
Quotient is 0 so you stop (you can actually continue if you want and get a bunch of 0s).

414 (b10) = 19E (b16)
Try it on your calculator.
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0


<< eLiu, i would like to tell you that all that work was worth something, but it really wasnt :)

thanks anyways, hehe
>>



lol :p

oh well...i guess ill go play CS now hehe ;)