How to resolve the algorithm Balanced ternary step by step in the МК-61/52 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Balanced ternary step by step in the МК-61/52 programming language
Table of Contents
Problem Statement
Balanced ternary is a way of representing numbers. Unlike the prevailing binary representation, a balanced ternary integer is in base 3, and each digit can have the values 1, 0, or −1.
Decimal 11 = 32 + 31 − 30, thus it can be written as "++−" Decimal 6 = 32 − 31 + 0 × 30, thus it can be written as "+−0"
Implement balanced ternary representation of integers with the following:
Test case With balanced ternaries a from string "+-0++0+", b from native integer -436, c "+-++-":
Note: The pages generalised floating point addition and generalised floating point multiplication have code implementing arbitrary precision floating point balanced ternary.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Balanced ternary step by step in the МК-61/52 programming language
Source code in the мк-61/52 programming language
ЗН П2 Вx |x| П0 0 П3 П4 1 П5
ИП0 /-/ x<0 80
ИП0 ^ ^ 3 / [x] П0 3 * - П1
ИП3 x#0 54
ИП1 x=0 38 ИП2 ПП 88 0 П3 БП 10
ИП1 1 - x=0 49 ИП2 /-/ ПП 88 БП 10
0 ПП 88 БП 10
ИП1 x=0 62 0 ПП 88 БП 10
ИП1 1 - x=0 72 ИП2 ПП 88 БП 10
ИП2 /-/ ПП 88 1 П3 БП 10
ИП3 x#0 86 ИП2 ПП 88 ИП4 С/П
8 + ИП5 * ИП4 + П4 ИП5 1 0 * П5 В/О
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Ela programming language
You may also check:How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Lua programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Vala programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the Perl programming language
You may also check:How to resolve the algorithm First-class functions step by step in the Lingo programming language