Convert from base 10 to base 3

1.9k Views Asked by At

I have a whole column in Google sheets with the numbers 1-400. Is there an easy way to convert these numbers to base 3?

1

There are 1 best solutions below

0
On BEST ANSWER

You could use a formula written in Apps Script:

function toTernary(decNumb) {
  var str = '';
  do {
    str = String(decNumb % 3) + str;
    decNumb = decNumb / 3 | 0;
  } while (decNumb >= 1);
  return parseInt(str);
}

Results:

decimal to ternary apps script

Usage:

  1. Tools > Script Editor > Blank
  2. Paste the code
  3. Save the code file
  4. Write the formula in your sheet as usual