I'm taking computer science courses and some digital design knowledge is required, so I'm taking digital design 101.
Image above is representing the conversion process of 8,4,-2,-1 to binary using K-map (Karnaugh map).
I have no idea why 0001, 0011, 0010, 1100, 1101, 1110 are marked as 'X'.
For 0001, 0011, 0010, they could be expressed as 8,4,-2,-1 as 0111, 0110, 0101.
And for 1100, 1101, 1110,
1110 can still be expressed as 1100 in 8,4,-2,-1 form as 1100.
rests cannot be expressed in 8,4,-2,-1 since 1100 is the biggest amount of number in 8,4,-2,-1 binary form (I think).
Is there something I'm missing?
I understand the excess-3 to binary code conversion provided from my textbook example ( m10-m15 are marked as 'X' since excess-3 were used to express only 0-9.)
According to the definition of BCD, 1 decimal digit (NOT one number) is represented by 4 bits.
The 4 given inputs can therefore represent only values from interval from 0 to 9.
The corresponding and complete truth-table looks like this:
decimal | 8 4 -2 -1 | decimal || BCD
/index | A B C D | result || W X Y Z
----------------------------------||---------
0 | 0 0 0 0 | 0 || 0 0 0 0 ~ 0
1 | 0 0 0 1 | -1 || X X X X
2 | 0 0 1 0 | -2 || X X X X
3 | 0 0 1 1 | -2-1=-3 || X X X X
4 | 0 1 0 0 | 4 || 0 1 0 0 ~ 4
5 | 0 1 0 1 | 4-1=3 || 0 0 1 1 ~ 3
6 | 0 1 1 0 | 4-2=2 || 0 0 1 0 ~ 2
7 | 0 1 1 1 | 4-2-1=1 || 0 0 0 1 ~ 1
8 | 1 0 0 0 | 8 || 1 0 0 0 ~ 8
9 | 1 0 0 1 | 8-1=7 || 0 1 1 1 ~ 7
10 | 1 0 1 0 | 8-2=6 || 0 1 1 0 ~ 6
11 | 1 0 1 1 | 8-2-1=5 || 0 1 0 1 ~ 5
12 | 1 1 0 0 | 8+4=12 || X X X X
13 | 1 1 0 1 | 8+4-1=11 || X X X X
14 | 1 1 1 0 | 8+4-2=10 || X X X X
15 | 1 1 1 1 | 8+4-2-1=9 || 1 0 0 1 ~ 9
The K-maps then match the truth-table by its indexes:
Using the K-maps, it can be indeed simplified to these boolean expressions:
W = A·B + A·¬C·¬D
X = ¬B·C + ¬B·D + B·¬C·¬D
Y = ¬C·D + C·¬D
Z = D
Related
I have 2-bit variable that is needed to be converted in another one. I made such a table
i1 i2 | o1 o2
0 0 | x x
0 1 | 0 1
1 0 | 1 0
1 1 | 0 1
But I cannot figure out how to do it except something like
(o1(i1,i2)&0b01 << 1) | (o2(i1,i2) & 0b01)
Let us we have binary number to fill out 9 spots with specific condition: 0 always comes before 1. the possible conditions is 10:
1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1
0 0 0 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0
Now lest us extent it to 0, 1, 2 with same rule. 0 should be always before 1 and/or 2. 1 should be before 1. Again, 9 spots are available to fill out.
I know that this yields to 55 combinations.
Question:
(1) what is the mathematical formulation to generalize this?
(2) How can I store all those 55 combinations? [any matlab code?]
Thanks
As the commenter said, the answer comes down to stars and bars. You can also think of this as counting the number of non-decreasing sequences i_1 <= i_2 <= ... <= i_k, where k is the number of symbols available and each i_j is a number between 0 and 9.
That said, here's a matlab script that generates all possibilities. Each row of the output matrix is one possible string of digits.
function M = bin_combs(L,k)
% L: length
% k: number of symbols
if k == 1
M = zeros(1,L);
else
M = zeros(0,L);
N = bin_combs(L,k-1);
for i = 1:size(N,1)
row = N(i,:);
for j=find(row==k-2)
new_row = row;
new_row(j:end) = new_row(j:end) + 1;
M = [M;new_row];
end
M = [M;row];
end
end
Some sample output:
>> size(bin_combs(9,3))
ans =
55 9
>> size(bin_combs(9,4))
ans =
220 9
I'd like to simplify this boolean function: f(a,b,c,d)=∑(1,3,5,8,9,11,15) to its minimal SOP and POS forms.
My solution is:
SOP: A'·B'·C'·D + A'·B'·C·D + A'·B·C'·D + A·B'·C'·D' + A·B'·C'·D' + A·B'·C·D + A·B·C·D
POS: (A+B+C+D)·(A+B+C'+D')·(A+B'+C+D')·(A'+B+C+D)·(A'+B+C+D')·(A'+B+C'+D')·(A'+B+C'+D')
Is it right?
Is there more to do?
The minimal SOP (sum of products) and the minimal POS (product of sums) of the given boolean function are depicted in these two Karnaugh maps.
Each of the necessary terms corresponds by color with the graphic representation.
Using the Karnaugh map for only four variables is really quick, but I could also use the Quine–McCluskey algorithm or rules of Boolean algebra for the minterms and maxterms in the truth table:
index A B C D output minterms maxterms
-------+---------+--------+-------------+--------------------
0 0 0 0 0 0 ~ M0: (a+b+c+d)
1 0 0 0 1 1 ~ m1: a'·b'·c'·d
2 0 0 1 0 0 ~ M2: (a+b+c'+d)
3 0 0 1 1 1 ~ m3: a'·b'·c·d
4 0 1 0 0 0 ~ M4: (a+b'+c+d)
5 0 1 0 1 1 ~ m5: a'·b·c'·d
6 0 1 1 0 0 ~ M6: (a+b'+c'+d)
7 0 1 1 1 0 ~ M7: (a+b'+c'+d')
8 1 0 0 0 1 ~ m8: a·b'·c'·d'
9 1 0 0 1 1 ~ m9: a·b'·c'·d
10 1 0 1 0 0 ~ M10: (a'+b+c'+d)
11 1 0 1 1 1 ~ m11: a·b'·c·d
12 1 1 0 0 0 ~ M12: (a'+b'+c+d)
13 1 1 0 1 0 ~ M13: (a'+b'+c+d')
14 1 1 1 0 0 ~ M14: (a'+b'+c'+d)
15 1 1 1 1 1 ~ m15: a·b·c·d
You can also check the correctness of your future solutions by using wolfram alpha.
I have to design a combinational circuit that accepts a 4-bit number and generate its triple, what does it mean? Can someone please give me an example of a specific input and its output so I can understand the question?
If you could give me also any hint for designing this circuit I would be very grateful.
Thank you.
You'll want to make a truth table and then derive the combinational logic from either boolean algebra (sum of truths), or from a k-map.
If, for example, the input is 0100 which is decimal 4, then the triple would be 12, or 1100. Since the highest number is 1111 (15), then your output has to be able to represent 45, or 101101 (6 bits).
Hence, you'll have something like:
Input | Output
-----------------
abcd uvwxyz
0000 | 000000
0001 | 000011
0010 | 000110
0011 | 001001
0100 | 001100
0101 | 001111
0110 | 010010
0111 | 010101
1000 | 011000
1001 | 011011
1010 | 011110
1011 | 100001
1100 | 100100
1101 | 100111
1110 | 101010
1111 | 101101
From that you can build a k-map for each output bit and find the minimum combinational logic required per output bit.
For example, to find the combinational logic for bit u then you would use the following k-map:
AB
00 01 11 10
CD 00 0 0 1 0
01 0 0 1 0
11 0 0 1 1
10 0 0 1 0
Which reduces to ACD + AB
Repeat for the other 5 bits (v-z) and you'll have the full combinational logic needed to implement the solution.
Start with a truth table:
IN OUT
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 3 0 0 0 0 1 1
2 0 0 1 0 6 0 0 0 1 1 0
3 0 0 1 1 9 0 0 1 0 0 1
4 0 1 0 0 C 0 0 1 1 0 0
5 0 1 0 1 F 0 0 1 1 1 1
6 0 1 1 0 12 0 1 0 0 1 0
7 0 1 1 1 15 0 1 0 1 0 1
8 1 0 0 0 18 0 1 1 0 0 0
9 1 0 0 1 1B 0 1 1 0 1 1
A 1 0 1 0 1E 0 1 1 1 1 0
B 1 0 1 1 21 1 0 0 0 0 1
C 1 1 0 0 24 1 0 0 1 0 0
D 1 1 0 1 27 1 0 0 1 1 1
E 1 1 1 0 2A 1 0 1 0 1 0
F 1 1 1 1 2D 1 0 1 1 0 1
Then use a standard technique such as a Karnaugh Map to deduce the input/output expressions.
I have an adjacency matrix. For example, the following,
+---+-------------------------------+
| | 1 2 3 4 5 |
+---+-------------------------------+
| 1 | 0 1 0 0 0 |
| 2 | 1 0 0 0 1 |
| 3 | 0 0 0 1 0 |
| 4 | 0 0 1 0 1 |
| 5 | 0 1 0 1 0 |
+---+-------------------------------+
how can we extract the following adjacency matrix, without for loops, where for each element (row or column) the neighbors of the already existed neighbors were added? For example, the element 3 has neighbor the element 4 so in the new adjacency matrix the element 3 will have neighbors the elements 4 and 5.
+---+-------------------------------+
| | 1 2 3 4 5 |
+---+-------------------------------+
| 1 | 0 1 0 0 1 |
| 2 | 1 0 0 1 1 |
| 3 | 0 0 0 1 1 |
| 4 | 0 1 1 0 1 |
| 5 | 1 1 1 1 0 |
+---+-------------------------------+
Best regards,
Thoth.
If A is your adjacency matrix, then the matrix you want is A2, where:
A2 = (A+A^2) > 0
This is because the square of an adjacency matrix has components s_ij, where s_ij is the number of paths of length two between i and j. (In fact (A^n)_ij is the number of paths from i to j of length n).
Therefore, if you add A (which contains all pairs joined by a path of length 1) to A^2 which contains all pairs linked by a path of length two, you'll get the number of paths of length 1 or 2. (And we only care if this is positive for this case). Paths of length two are paths to the neighbours of neighbours.
You might want to set the diagonal back to zero though