Bonjour,
j'ai fait une petit programme pour tester les operateurs logiques en C99,
je poste la partie qui alimente les deux entrees d'une eventuelle porte logique,
j'aurai voulu avoir vos avis et critiques et si je merite l'excommunication .
le programme est compilable tel quel et affiche le tableau ci-dessous:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
----------------
|binaire| deci |
----------------
| 0 | 0 |  0   |
----------------
| 0 | 1 |  1   |
----------------
| 1 | 0 |  2   |
----------------
| 1 | 1 |  3   |
----------------
| 0 | 0 |  4   |
----------------
| 0 | 1 |  5   |
----------------
| 1 | 0 |  6   |
----------------
| 1 | 1 |  7   |
----------------
pas taper SVP

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*   oscil.c
compteur binaire sur deux bits
 
 14 Avril 2013
 JulieCarree
 
*****************************************************************
*    commande compile : gcc -std=c99  -Wall oscil.c -o oscil    *
*    commande execute : ./oscil                                 *
*****************************************************************
*/
 
#include <stdio.h>
#include <stdbool.h>
 
bool TAU ( bool bit_0, bool bit_1);      /* Tautologie               */
bool CTR ( bool bit_0, bool bit_1);      /* Contradiction            */
void oscilateur_2bits ( bool *bit_0, bool *bit_1, size_t compt );
 
int main (void)
{
        const char ligne[] = "----------------\n";
        const char titre[] = "|binaire| deci |\n";
        size_t compt = 0;
        bool bit_0 = false;
        bool bit_1 = false;
 
        printf ( "\n%s%s", ligne, titre );
        for ( compt =0; compt < 8; ++compt )
        {
                printf ( "%s", ligne );
                oscilateur_2bits ( &bit_0, &bit_1, compt );
                printf ( "| %d | %d |  %d   |\n", bit_1, bit_0, compt );
        }
 
        printf ( "%s", ligne );
        return 0;
}
 
/********************************/
 
/****************/
void oscilateur_2bits ( bool *bit_0, bool *bit_1, size_t compt )
{
        compt %= 4;
        if ( compt == 3 )
                *bit_0 = *bit_1 = TAU ( bit_0, bit_1 );   /* 1 1 */
 
        if ( compt == 2 )
        {
                *bit_0 = CTR ( bit_0, bit_1 );            /* 1 0 */
                *bit_1 = TAU ( bit_0, bit_1 );
        }
 
        if ( compt == 1 )
        {
                *bit_0 = TAU ( bit_0, bit_1 );            /* 0 1 */
                *bit_1 = CTR ( bit_0, bit_1 );
        }
 
        if ( compt == 0 )
                *bit_0 = *bit_1 = CTR ( bit_0, bit_1 );   /* 0 0 */
 
        return ;
}
 
/****************/
bool TAU ( bool bit_0, bool bit_1)   /*   (A NAND B) OR (A AND B)   toujours vrai   */
{
        return ( bit_0 && bit_1 ) || !( bit_0 && bit_1 );
}
 
/****************/
bool CTR ( bool bit_0, bool bit_1)   /*   (A OR B) AND (A NOR B)   toujours faux    */
{
        return ( bit_0 || bit_1 ) && !( bit_0 || bit_1 );
}
 
/****************/