/media/sda-magnetic/david/Dok-15-2023-11-27/fernuni-hagen/cs-i-ii/old-cs-2-03/cs/cs-aufgI.txt


Disjunktive Normalform f(x1,x2,x3) = ((not x1) and x2 and (not x3)) or (x1 and x2 and (not x3)) or (x1 and x2 and x3)
Kojunktive Normalform f(x1,x2,x3) = (x1 or x2 or x3) and (x1 or x2 or (not x3)) and (x1 or (not x2) or (not x3)) and ((not x1) or x2 or x3) and ((not x1) or x2 or (not x3))


 5 0 1 0 1  1
 7 0 1 1 1  1
 9 1 0 0 1  1
11 1 0 1 1  1
13 1 1 0 1  1
14 1 1 1 0  1
15 1 1 1 1  1


Gruppe 2

 5 0 1 0 1  1
 9 1 0 0 1  1
 
Gruppe 3

 7 0 1 1 1  1
11 1 0 1 1  1
13 1 1 0 1  1
14 1 1 1 0  1

Gruppe 4

15 1 1 1 1  1

5;7     0 1 - 1
5;13    - 1 0 1
9;11    1 0 - 1
9;13    1 - 0 1
7;15    - 1 1 1
11;15   1 - 1 1
13;15   1 1 - 1
14;15   1 1 1 -

(not x3 and x2 and x0) or 
(x2 and not x1 and x0) or
(x3 and not x2 and x0) or
(x3 and not x1 and x0) or
(x2 and x1 and x0) or
(x3 and x2 and x0 or
(x3 and x1 and x0) or
(x3 and x2 and x1) or

        5   7   9   11  13  14  15

5;7     *   *
5;13    *               *
9;11            *   *
9;13            *       *    
7;15        *                   *
11;15               *           *
13;15                   *       *
14;15                       *   *

        *   *   *   *   *   *   *
        

        5   7   9   11  13  14  15

5;7     *   *
9;11            *   *
13;15                   *       *
14;15                       *   *

(not x3 and x2 and x0) or (x3 and not x2 and x0) or (x3 and x2 and x0) or (x3 and x2 and x1)

c) KV-Diagramm

                            (not x2) and (not x1)       (not x2) and x1     x2 and x1       x2 and (not x1)
                                00                          01                  11                 10
        
(not x4) and (not x3)   00      1                           0                   0                  0
(not x4) and x3         01      0                           0                   0                  1
x4 and x3               11      1                           0                   1                  0
x4 and (not x3)         10      1                           0                   1                  0

x4 and x3 and (not x2) and (not x1), x4 and (not x3) and (not x2) and (not x1) => x4 and (not x2) and (not x1)
x4 and x3 and x2 and x1, x4 and (not x3) and x2 and x1 => x4 and x2 and x1

vereinfacht: 

not x4 and not x3 and not x4 and not 3      or
not x4 and x3 and x2 and not x1             or
x4 and (not x2) and (not x1)                or
x4 and x2 and x1

     ____               ____     ____
x1 --|   |--------------|   |----|   |-----
     | & |       _______|>=1|  __|>=1|    |
x2 --|___|      |       |___| |  |___|    |
                |             |           |
     ____       |             |           |
x2 --|   |------|             |           |
     | & |                    |           |
x3 --|___|                    |           |
                              |           |
     ____                     |           |
x1 --|   |--------------------|           |  _____
     | & |                                |__|    |
x3 --|___|                                   | &  |------
                                          |--|____|
                                          |
     ____                                 |
x4 --|   |--------------------------------|
     |>=1|
x5 --|___|
     
     
g(x1, x2, x3, x4) = ((x1 or x2) and x3) or (x2 and (x3 or x4))
     
   x4x3x2x1 y
 0 0 0 0 0  0
 1 0 0 0 1  0
 2 0 0 1 0  0
 3 0 0 1 1  0
 4 0 1 0 0  0
 5 0 1 0 1  1
 6 0 1 1 0  1
 7 0 1 1 1  1
 8 1 0 0 0  0
 9 1 0 0 1  0
10 1 0 1 0  1
11 1 0 1 1  1
12 1 1 0 0  0
13 1 1 0 1  1
14 1 1 1 0  1
15 1 1 1 1  1

Ein etwas alternativer Lösungsweg:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define not !
#define and &&
#define or ||


int main (void) {
    int x0, x1, x2, x3, x4;
    time_t t;
    int i;

    
    srand((unsigned) time(&t));
    
    for (i = 0, x4 = 0;  x4 <= 1;  x4++) {
        for (x3 = 0;  x3 <= 1;  x3++) {
            for (x2 = 0;  x2 <= 1;  x2++) {
                for (x1 = 0;  x1 <= 1;  x1++, i++) {
                    //for (x0 = 0;  x0 <= 1;  x0++, i++) {
                        printf( "%2i %i %i %i %i", i, x4, x3, x2, x1);   
                        printf( "  %i\n", ((x1 or x2) and x3) or (x2 and (x3 or x4)));
                    //}
                }
            }
        }
    }
}

c) Schaltfunktion:

(x2 and x3)

x1 and (x2 and x3)
x4 and (x2 and x3)

x1 and (x2 and x3) or x4 and (x2 and x3)

Mit dem alternativen Lösungsweg: 

 0 0 0 0 0  0
 1 0 0 0 1  0
 2 0 0 1 0  0
 3 0 0 1 1  0
 4 0 1 0 0  0
 5 0 1 0 1  0
 6 0 1 1 0  0
 7 0 1 1 1  1
 8 1 0 0 0  0
 9 1 0 0 1  0
10 1 0 1 0  0
11 1 0 1 1  0
12 1 1 0 0  0
13 1 1 0 1  0
14 1 1 1 0  1
15 1 1 1 1  1

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define not !
#define and &&
#define or ||


int main (void) {
    int x0, x1, x2, x3, x4;
    time_t t;
    int i;

    
    srand((unsigned) time(&t));
    
    for (i = 0, x4 = 0;  x4 <= 1;  x4++) {
        for (x3 = 0;  x3 <= 1;  x3++) {
            for (x2 = 0;  x2 <= 1;  x2++) {
                for (x1 = 0;  x1 <= 1;  x1++, i++) {
                    //for (x0 = 0;  x0 <= 1;  x0++, i++) {
                        printf( "%2i %i %i %i %i", i, x4, x3, x2, x1);   
                        printf( "  %i\n", (x1 and (x2 and x3)) or (x4 and (x2 and x3)));
                    //}
                }
            }
        }
    }
}

Aufgabe 3

a) 

Kleinste negative Zahl, in Zweierkomplementdarstellung: 1 0000 
Dezimal: -16 (Weil -(2^(n-1)) = -(2^4) = -16 Außerdem: Rechnen wir 10000 um

: Wir ziehen -1 ab: Dann haben wir 01111, dann tun wir die Bits umkehren: 10000 Das ist 16, weil 1111 15 ist. Das kann man sich einfach merken, weil der Wertbereich von 0000 bis 1111 geht, es 16 Zahlen gibt, aber der Wertebereich bei 0 begint

Größte Positive Zahl: 01111: Das ist 15 - und wir wir wissen 2^(n+1)-1

23 mod 2 = 1, 23 div 2 = 11
11 mod 2 = 1, 11 div 2 = 5
5 mod 2 = 1, 5 div 2 = 2
2 mod 2 = 0, 2 div 2 = 1
1 mod 2 = 1, 1 div 2 = 0

Also lautet die Zahl: 10111

Dafür nehmen wir den Linux-KDE-Taschenrechner, um das Ergebnis zu verifizieren

Und das Ergebnis ist richtig

-3 umwandlen in 4 Bit: Das sind 00011

Dann Einerkomplement: 11100

Dann zweierkomplement 11101

Addieren wir mal die -3 zur 3, um zu sehen ob alles richtig ist

  00011
+ 11101
c 11110
-------
  00000
  
Right!


Also zu b3) hängt davon ab, ob wir mit natürlichen oder ganzen Zahlen arbeiten: Erst: Natürliche Zahlen:

101011

2^0 + 2^1 + 2^3 + 2^5

= 1 + 2 + 8 + 32 = 43

Linux-Taschenrechner sagt: Richtig,

dann ganze Zahlen

101011 - 1 = 101010 (Weil Zweierkomplement)
not 101010 = 010101 ( Weil Zweierkomplement)

010101 = 2^0 + 2^2 + 2^4 = 16+4+1 = 21

Addieren wir mal 010101 zu 101011

  010101
+ 101011
--------
c 111110 
--------
  000000
  
Sieht richtig aus. 

b4)

Ich verstehe die Frage nicht: Welche Zahl, wird dargestellt, wenn 010110 ist eine Zahl in Zweierkomplementdarstellung - dann positiv - werde ich machen

Oder: Wie stellt man 010110 in Zweierkomplemntdarstellung dar - werde ich auch machen

010110 

ist: 2^1+2^2+2^4 = 16+4+1 = 21. Wir dürfen so rabiat vorgehen, weil kein Vorzeichen da ist. Das heißt die Zahl ist positiv und dafür gilt das übliche

In zweierkomplementdarstellung sieht die Zahl so aus:

101001 + 1 = 101010
    
    
a1  a0  b1  b0  s2  s1  s0
0   0   0   0   0   0   0   
0   0   0   1   0   0   1
0   0   1   0   0   1   0
0   0   1   1   0   1   1
0   1   0   0   0   0   1
0   1   0   1   0   1   0
0   1   1   0   0   1   1
0   1   1   1   1   0   0   
1   0   0   0   0   1   0
1   0   0   1   0   1   1
1   0   1   0   1   0   0   
1   0   1   1   1   0   1   
1   1   0   0   0   1   1
1   1   0   1   1   0   0   
1   1   1   0   1   0   1
+++++++++++++++++++++++++
1   1   1   1   1   1   1

Wie wir jetzt vermuten können, tritt der Fall auch nur dann ein, wenn wirklich alle "Eingänge" auf 1 stehen.

wir müssen bedenken unser Ausgangswertebereich geht bis s^n

Nein, falsch, da habe ich etwas falsch gelesen. Das wäre einfach. Aber der Bus am Ausgang ist so groß, wie am Eingang. Also noch Mal:

a1  a0  b1  b0  s2  s1  s0
0   0   0   0   0   0   0   
0   0   0   1   0   0   1
0   0   1   0   0   1   0
0   0   1   1   0   1   1
0   1   0   0   0   0   1
0   1   0   1   0   1   0
0   1   1   0   0   1   1
0   1   1   1   1   0   0   
1   0   0   0   0   1   0
1   0   0   1   0   1   1
1   0   1   0   1   0   0   
1   0   1   1   1   0   1   
1   1   0   0   0   1   1
1   1   0   1   1   0   0   
1   1   1   0   1   0   1
+++++++++++++++++++++++++
1   1   1   1   1   1   1

Dann habe ich aber genau deswegen eine gute Idee - sobald s2 auf 1 steht, sagt der Multiplexer: 11

Das wäre diesen Fälle


a1  a0  b1  b0  s2  s1  s0
0   1   1   1   1   0   0   
1   0   1   0   1   0   0   
1   0   1   1   1   0   1   
1   1   0   1   1   0   0   
1   1   1   0   1   0   1
1   1   1   1   1   1   1

Ich erlaube mir, weil, das Zeichnen so mühsam ist, eine Formel hin zu schreiben. Dabei führe ich den Operator

+2 ein. Er deutet auf HalbaddiererAddierer hin und +, er deutet auf Addierer hin

Also, jetzt:




a1  a0  b1  b0  s2  s1  s0
0   0   0   0   0   0   0   
0   0   0   1   0   0   1
0   0   1   0   0   1   0
0   0   1   1   0   1   1
0   1   0   0   0   0   1
0   1   0   1   0   1   0
0   1   1   0   0   1   1
1   0   0   0   0   1   0
1   0   0   1   0   1   1   
1   1   0   0   0   1   1
   
c0 = 0
s0 = a0 xor b0 xor c0
c1 = (a0 and b0) or (a0 or b0) and c0
s1 = a1 xor b1 xor c1
c2 = (a1 and b1) or (a1 or b1) and c1

So, lautet die Gleichung für den Parallel-Addierer ohne Sättigung. Jetzt mit Sättigung

c0 = 0
s0 = [a0 xor b0 xor c0] or c2
c1 = (a0 and b0) or (a0 or b0) and c0
s1 = [a1 xor b1 xor c1] or c2
c2 = (a1 and b1) or (a1 or b1) and c1

Das Lustige ist: Das stimmt auf jeden Fall: Weil, sobald wir s2 gesetzt haben, verlassen wir den Bereich 2^(n-1)-1. Aber! Das ist garantiert. Die größte Zahl ist 11.  Oder so. Aber, was ich hingeschrieben habe ist eine Forml.
Das ist natürlich verführerisch und wichtig. Weil: Schauen Sie sich Intel an - selbst, wenn es GUI's gibt, die werden etwas wie ein Intel-VHDL verwenden. Das heißt, sie schreiben es in VHDL als Formel und malen keine Bilder. 

Diese Formel hat einen Nachteil - das würde man bei VHDL stark merken: Sie hat eine Rückkoplung. Genrell nicht falsch. Aber sie hat eine Rückkopplung. Um das Problem vollständig zu lösen: Bauen wir zwei solcher Schaltungen. Und die eine Schaltung ergibt, mit dem anderen das OR. Also


C0 = 0
S0 = A0 xor B0 xor C0
C1 = (A0 and bB) or (A0 or B0) and C0
S1 = A1 xor B1 xor C1
C2 = (A1 and B1) or (A1 or B1) and C1

c0 = 0
s0 = [a0 xor b0 xor c0] or C2
c1 = (a0 and b0) or (a0 or b0) and c0
s1 = [a1 xor b1 xor c1] or C2
c2 = (a1 and b1) or (a1 or b1) and c1

wichtig hier: Groß und Kleinschreibung