Thread: Ternary Digits

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Manila, Philippines
    Posts
    30
    Rep Power
    1

    Ternary Digits


    Suppose a new computer uses radix-3 (ternary) logic instead of radix-2 (binary) logic to represent unsigned integers.

    What is the largest value that can be represented by 6 ternary digits?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    3^6
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Manila, Philippines
    Posts
    30
    Rep Power
    1
    If I were to convert the decimal 47 to radix-3, do I divide it repeatedly by 3?
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    No. To convert something to another base, you must deal with powers. Each digit represents a power of the base. In decimal, the first (right most) digit is 10^0 times the value of the number. The second digit is 10^1 times the value of the digit. So in base 10:
    12 = ((10^0)*2)+((10^1)*1)

    For binary it's the same rule:
    1101 = ((2^0)*1)+((2^1)*0)+((2^2)*1)+((2^3)*1) = 13

    And finally, for trinary you'd calculate it the same way:
    2101 = ((3^0)*1)+((3^1)*0)+((3^2)*1)+((3^3)*2) = 64

    To get the answer in the other way, work backwards. Start with figuring out how many digits there will be. The highest number you can represent with 3 digits of trinary is 222, which (by our rules above) is equal to 26, so you need 4 digits. Now, work through those digits largest-to-smallest:
    3^3 times WHAT is less than or equal to 47? 1. The first digit is 1. Subtract ((3^3)*1) from your number and move on.
    3^2 times WHAT is less than 20? 2. The second digit is 2.
    3^1 times WHAT is less than 2? Nothing, 3 > 2. The third digit is 0.
    3^0 times WHAT is less than or equal to 2. 2, obviously.

    47 in trinary is 1202.

    Check your work:
    1202 = ((3^0)*2)+((3^1)*0)+((3^2)*2)+((3^3)*1) = 47
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Manila, Philippines
    Posts
    30
    Rep Power
    1
    Question 1:
    3^6 = 729
    I just want to confirm if the largest value that can be represented by 6 ternary digits is 729 or 728 (including 0)?

    Question 2:
    I seem to have arrived to (1202) base 3 by repeated division and taking the remainders.
    Code:
    http://s23.postimg.org/wm9vfhgpn/DSC_0170.jpg
    We are taught the same way for binary, octal, and hex -- dividing the decimal by radix until reaching 0 for the quotient then writing the remainders bottom-up.

    Thank you ManiacDan for your assistance.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Sorry, I wasn't QUITE right before. The largest number represented by 6 ternary digits is ((3^6)-1), much like for 6 binary digits is ((2^6)-1).

    Short proof, the largest possible number with 6 digits:
    ((3^0)*2)+((3^1)*2)+((3^2)*2)+((3^3)*2)+((3^4)*2)+((3^5)*2) = 728.

    You don't "include zero" for determining the largest number. You can represent 729 numbers, the highest of which is 728.

    The repeated-division method works as well, I prefer not to do it that way because it's a bit of a cheat. You're using a trick in base-10 math that happens to work out properly for base-3 math. Why not just do it in base-3? (It's slower my way unless you think in that base commonly or are able to do the math in your head without going crazy)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Manila, Philippines
    Posts
    30
    Rep Power
    1
    Like in my other thread where 2^5 = 32, the signed decimal range would be -16 to +15, which is 32 integers "including 0". I am thinking in the algebra/real number line concept, but it is good to see the mathematical proof behind it.

    I tried with another odd number, radix-7 and the repeated division worked well enough.
    (158) base 10 = (314) base 7

    If it worked on radix-3 ONLY, then it is indeed sort of a "cheat" for radix-3.

    If it is a solution that works consistently on both odd and even bases, I guess it is better appropriated as an "alternative method" for converting decimal to any radix-x.

    Well, there goes my two cents.

    Thank you for showing me the power method though. It will be a useful reference and good way to double-check things.
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,923
    Rep Power
    1045
    Hi,

    the repeated division is the standard algorithm for converting bases. In Germany, we call it "reverse Horner's scheme", but there may be different names.

    No idea why ManiacDan calls it a "cheat" and claim that it only works for base 10. It works for any two bases.

    If you wanted to, say, get the base 5 representation of 1526(7), you'd divide 1526(7) by 5 (in base 7). The remainder is the last digit of the base 5 representation. And the result is again divided by 5 etc.

    This is very simple and quick. The "alternative" described by ManiacDan may work for small numbers, but it's completely inappropriate for bigger numbers or actual algorithm. Or would you tell me real quick what's the next biggest power of 42 for 52398257916?
    Last edited by Jacques1; September 27th, 2013 at 04:44 AM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Manila, Philippines
    Posts
    30
    Rep Power
    1
    Originally Posted by Jacques1
    It works for any two bases.

    If you wanted to, say, get the base 5 representation of 1526(7), you'd divide 1526(7) by 5 (in base 7).
    Thank you. This is good to know. So far, I have only tried it for base 10.

IMN logo majestic logo threadwatch logo seochat tools logo