Code Monkey home page Code Monkey logo

minitalk's Introduction

minitalk-42

The purpose of this project is to code a small data exchange program using UNIX signals.

temps de travail

3 heures

encode

void	encode(pid_t pid, char *str)
{
	char	c;
	int		bin;
	int		char_size;
	int		i;
	int		len;

	i = 0;
	len = ft_strlen(str) + 1;
	while (i < len)
	{
		c = str[i];
		char_size = 0;
		while (char_size < 8) // on fais l'operation sur chaque bit du char (8-bit)
		{
			usleep(200);
			bin = c & 0b10000000; // on met le premier bit dans bin donc 0b1000000 = 0b1010000 & 0b1000000
			c = c << 1; // on decale les bit de c de 1 vers la droite 01010000 -> 1010000
			char_size++;
			if (bin)
				kill(pid, SIGUSR2); // si bit fort (1)
			else
				kill(pid, SIGUSR1); // si bit faible (0)
		}
		i++;
	}
}

decode

void	decoder(int sig_no) // call a chaque signal
{
	static char	char_build = 0;
	static int	char_size = 0;
	static char	*string = NULL;

	char_build = char_build << 1;
	if (sig_no == SIGUSR2)
		char_build = char_build | 0b00000001; // si bit fort on applique le masque donc on set le dernier bit a 1
	char_size++;
	if (char_size == 8)
	{
		char_size = 0;
		//char_build is the char
	}
}

minitalk's People

Contributors

froz42 avatar

Watchers

 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.