Suppose that instead of binary or decimal representation of integers, we have ternary, along with 3’s complement, representation of integers, i.e., integers are represented using three digits, viz., 0, 1,2. For example, the integer 47 is represented as 01202 = (in decimal) 1. 33 + 2. 32 + 0. 31 + 2. 30, where, the leading zero indicates positive sign. And the integer (– 47 ) in 3’s complement is represented by 11021, the leading 1 indicates negative sign. The other digits, except the right-most, in the representation of (– 47) are obtained by subtracting from 2 the corresponding digit in 47’s representation, and then adding 1 (the representation of – 47 is obtained as 11020 + 00001).
Write a program for the arithmetic (negation of an integer, addition, subtraction and multiplication of two integers) of
integers using 3’s complement representation. The program should include a procedure for calculating each of negation of an integer, addition, subtraction and multiplication of two integers. The integers will use 8-ternary digit positions, in which the left-most position will be used for sign.
Using your program find the ternary representation of each of the decimal numbers 345, -- 297, 18 and ( (345 -- 297) * 18)