Pseudoternary Encoding Documentation and Implementation


I have created a program with c++ to show the process of solving the Pseudoternary encoding. Then i illustrate the encoding scheme with the javascript

C++ Documentation

The c++ program has a global array that accepts various numbers, (1 and 0. Then i create the Pseudo function which accepts an array variable as parameter. Then i use a for loop that starts and ends depending on the array elements. I declare a boolean variable called down and assign it to false. Then i use selection structure. If one of the elements is 1: it should output "no line", else if one of the elements is 0 i toggle the boolean variable to be true. Then with two more if statements i compate the boolean variable with the following way: If the boolean value is true, it prints "pulse goes up" else it prints "pulse goes down". Then in the main function i call that pseudo function and i pass in the global varriable array. Once the program compiles it shows step by step the procedure of the Pseudoternary encoding scheme. The comments in my code show some notes on how things work

that you can change the inputs of any numbers of your choice ( see line 5) on the Libraries & Global variable section

View, edit and run my c++ code online at this link
C++ File is also included in the root


file Pseudoternary.cpp

Libraries & global variable

//macro creation, that accepts as parameter the array. It is used for the for loop to end depending on the number of the elements in the array
#define arrayLength(inputs) (sizeof((inputs)) / sizeof((inputs)[0])) 
using namespace std;
int inputs[] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 }; //global array, elements should only be 0 or 1

The function

void Pseudo(int a[]) //function definition:  accepts an array as parameter
    static int count = 0; //counts the number of steps

    bool down = false; //boolean value

    for (int b = 0; b < arrayLength(inputs); b++)
        if (a[b] == 1) //if an element is 1..
            cout << "Step " << count << ": "
                 << "No line value is 1\n";

        else if (a[b] == 0) //if an element is 0

            down = !down; //boolean value will toggle for each element in the array with the value 0

            if (down == true) {
                cout << "Step " << count << ": Goes up\n";
            else {

                cout << "Step " << count << ": Goes down\n";
        else { //if an element in the array is not 0 or 1..
            cout << "Step " << count << " is wrong, please replace the array element " << count - 1 << " with 0 or 1!" << endl;

Main function

		 int main()
{    cout << "Pseudoternary encoding scheme\nImplementation of ";

    for (int b = 0; b < arrayLength(inputs); b++) {
        cout << inputs[b] << ","; //outputs the array numbers
    cout << endl
         << endl;
    cout << "Implementation steps:\n\
         << endl;

    Pseudo(inputs); //function call

Program Output

Brief explanation:

Encoding Scheme

Same as:

-Output "No line value is 1" means that there is no line signal
-Output "Goes up" means that there is positive level
-Output "goes down" means there is negative level

Javascript Documentation

Javascript code is pretty much the same logic as in c++. It accepts inputs from a text box (only 1 or 0 otherwise you will get an error). Then i use two functions, pseudo() and gettext(). The pseudo is responsible for detecting one by one the inputs (as an array) and displaying the appropriate image. The gettext() function is responsible for retrieving the text from the input text. Then i fetch the index value from the string inputText one by one. Note that the inputs from the text is actually a bunch of strings so i have to call the parseInt function to convert it to integers. Finally i call the pseudo function. I also use some css to style the down image with some margin top.

Run my Html code with the javascript online at this link (View it horizontally)
Or go directly to the Illustration page


file illustration.html


Try your own input here