Try   HackMD

2017q3 Homework1 (ternary)

contributed by <function86437>

Ternary numeral system

Ternary 是一個三進制的系統,又稱為 (base-3) ,儲存資料的位元稱為 trit (trinary digit) ,對比二進制的 bit ,在 ternary 中因表示法的不同又分為 unsigned ternary 與 balanced ternary ,對應的表示法為 0, 1, 2-1, 0, +1 (T, 0, 1) 。

  • [wikipedia-Balanced ternary]中討論在二進制中 n bits 能表示的最大數字為
    2n
    -1,那 ternary n bits 能表示的最大數字是否為
    3n
    -1呢?
    給定一個數字為
    N(b,d)
    ,其中 b 為基底 d 為次方,給個單位能表示最大數為 b-1 。

    N(b,d)=(b1)bd1+(b1)d2+...+(b1)1+(b1)0,

    N(b,d)=(b1)(bd1+bd2+...+b1+1),

    N(b,d)=(b1)M.

    bM=bd+bd1+...+b2+b1,and

    M=bd1bd2...b11,so

    bMM=bd1,or

    M=(bd1)/(b1).Then

    N(b,d)=(b1)M,

    N(b,d)=(b1)(bd1)/(b1),and

    N(b,d)=bd1.

    例如:
    N(3,3)=331=26=2×32+2×31+2×30=18+6+2

Balanced Ternary

balanded ternary 的表示法為 -1, 0, 1,可以表示所有的整數,而且不需要額外的位元儲存正負號。

例如:

9dec=T00bal3
最左邊的第一個非零項本身就包含正負號。
9dec=1×32+0×31+0×30=T00bal3

我們舉幾個例子:

10bal3=1×31+0×30=3dec
10Tbal3=1×32+0×31+(1)×30=8dec

8dec=1×32+0×31+(1)×30=10Tbal3

23dec=1+13=1×30+1×31=T.1bal3
但在遇到某些浮點數的時候,會出現有不只一種表示法。
例如:
0.5dec=1×13+1×19...=0.Tbal3

又可表示為
0.5dec=1+0.5dec=T+0.1bal3=T.1bal3

Ternary 基本運算

在真值表上 Ternary 相較於 Bianry 多了一個 unknown 的值,對應-1,0,1 如下表:

truth value
true +
unknown 0
false -

Ternary computing介紹中,下圖的 ternary multiplexer 取決於輸入 A 的訊號,輸出相對應值,例如:當 A=-1 輸出 pin腳 N , A=0 輸出 pin腳 O, A=1 輸出 pin腳 P ,會根據 N,O,P數值不同,而有不同的功能,是一個unary functions

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這是一個輸出 A = A + 1 與 A = A - 1 的功能

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

計算 A 與 0 的最大值、最小值

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


三個 multiplexer 可以實做出一個 half adder,這邊可以發現第二層的 N,O,P 數值是由前面運算完後的結果決定的。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

從右邊真值表不難看出只有在 A,B同時為-1時輸出-1與 A,B同時為1時輸出1,其餘為0,這個電路可作為之後判斷進位的功能。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

全加器類似二元運算中的全加器,都是由兩個半加器組成

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

overflow 的電路看起來很複雜,但以 Cout 的結果回推回來就比較容易理解,考慮進位 Cin 的輸入:

  • 若 Cin=-1,A, B三種狀況
    • A=-1且 B=0
    • A=0 且 B=-1
    • A=-1 且 B=-1
  • 若 Cin=0, A,B必同時為-1或1
  • 若 Cin=1, A, B三種狀況
    • A=1 且 B=0
    • A=0 且 B=1
    • A=1 且 B=1
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Balanced Ternary 實際應用:

重點

參考資料