Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

converting bases

Name: Anonymous 2009-01-21 22:48

ok, so i need to convert 2009 base 10 to a base 3 numeral for some liberal arts shit(i suck at math). so everythings going fine until i get to the the 3^2 spot and come up with fucking 7 as a digit. what do you do if you come up with a digit thats higher than the base? when i looked it up the answer was 2202102, but i dont understand how that can be. can anyone help?

Name: Anonymous 2009-01-21 23:53

In base 10, digit place values from right to left progress 1, 10, 100, 1000, and so on with progressive powers of 10.  In base 3, digit places values progress (using base 10 notation) 1, 3, 9, 27, and so on with progressive powers of 3, but in base 3 notation those numbers would be symbolized as 1, 10, 100, 1000, and so on.  So in base 3 notation, 1111 symbolizes base 10 27+9+3+1 which is 40.

The largest power of 3 that base 10 2009 is greater than is 3^6, which is 729.  We can remove 2*729 from 2009, leaving 551.  We can next remove 2 of 3^5 or 486, leaving 65.  We can't remove any 3^4 from 65, so that's 0 of them, but we can remove 2 of 3^3 from 65, leaving 11.  We can remove 1 of 3^2 from 11, leaving 2.  We can't remove any 3^1 from 2, so that's 0 of them, but we can remove 2 of 3^1 from 2, leaving zero, and we are done.  The digits for base 10 2009 written in base 3 notation are those multiplying factors of powers of 3 that we removed from 2009:  2202102.

Name: Anonymous 2009-01-22 0:01

Oh damn, I have a typo up there, change "remove 2 of 3^1 from 2" to "remove 2 of 3^0 from 2".

I'll type it this way:
2009 = 2(3^6) + 2(3^5) + 0(3^4) + 2(3^3) + 1(3^2) + 0(3^1) + 2(3^0)

The general idea is to take your given number and substract the greatest power of the desired base from it that can be subtracted from it and do that as many times as you can, and then work your way down, subtracting successively lesser powers of the desired base, keeping track of how many of each power of the desired base was subtracted out, as those counts will be the digits for the number written in the desired base.

Name: 4tran 2009-01-22 3:34

A faster algorithm is to divide by 3, and record the remainder each time.  Reverse this number, and you're good to go.

2009/3 = 669R2
669/3 = 223R0
223/3 = 74R1
74/3 = 24R2
24/3 = 8R0
8/3 = 2R2
2/3 = 0R2

Thus, in base 3, 2009 = 2202102
Do the same algorithm on this base 3 number, and you'll see why the algorithm works.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List