Max
Max

Reputation: 33

Convert from base 10 to base 3

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?

Upvotes: 3

Views: 2012

Answers (1)

ZygD
ZygD

Reputation: 24356

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

Upvotes: 5

Related Questions