Code Monkey home page Code Monkey logo

trit_array_cpp's Introduction

trit_array_cpp

C++ header-only library of a trit array

Description and examples

  • trit - ternary digit
  • in balanced ternary, each digit has one of 3 values: โˆ’1, 0, or +1
#include <iostream>
#include "trit_array.hpp"

int main() {
	std::cout << "Hello world!" << std::endl;

	// Create a two-dimensional array of trits
	base3::trit_array_2d array_2d;

	// Set the size of a two-dimensional array
	const int SIZE_X = 1000;
	const int SIZE_Y = 100;
	//base3::trit_array_2d array_2d(SIZE_X, SIZE_Y); - this option is also possible
	array_2d = base3::trit_array_2d(SIZE_X,SIZE_Y);

	// Set the value of the trit
	array_2d.set(55, 34, base3::BASE3_TRUE); // Set +1
	array_2d.set(156, 87, base3::BASE3_FALSE); // Set -1
	array_2d.set(3, 8, base3::BASE3_NULL); // Set 0

	// Get the value of trit
	int state = array_2d.get(55, 34);
	if(state == base3::BASE3_TRUE) std::cout << "true" << std::endl;

	// size of two-dimensional array of trit
	int data_size = array_2d.size();
	std::cout << "size: " << data_size << std::endl << std::flush;

	// pointer to array data
	unsigned char *point_data = array_2d.data();

	// Initialize a new array of trites with an array of bytes
	unsigned char *array_data = new unsigned char[data_size];
	std::copy(point_data, point_data + data_size, array_data);
	base3::trit_array_2d new_array_2d(SIZE_X, SIZE_Y, array_data);

	return 0;
}

trit_array_cpp's People

Contributors

newyaroslav avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.