Writing A'B'CD+ABC' using two inverters and 5 2:1 multiplexers - logic

The question says draw F(A,B,C,D)=∑(3,7,11,12,13). I derived A'B'CD+ABC'. I am trying to draw it using two inverters and 5 2:1 multiplexers but i couldn't connect the output to the separate components i wrote. I know the correct answer but i just couldn't understand it.
Here's the correct solution
Why is the last mux connected to the 0 instead of 1 like we did all the other components? And why did they give 1 to 1 in mux in the answer?

OK, then maybe this will help:
F(A,B,C,D)=∑(3,7,11,12,13).
w/ 2 nots; 5 2/1 muxs
truth table
ABCD R
0000 0
0001 0
0010 0
0011 1
0100 0
0101 0
0110 0
0111 1
1000 0
1001 0
1010 0
1011 1
1100 1
1101 1
1110 0
1111 0
kmap
\ CD 00 01 11 10
AB \
00 0 0 1 0
01 0 0 1 0
11 1 1 0 0
10 0 0 1 0
expression
ABC'+A'CD+B'CD
simplifying
ABC'+(A'+B')CD
ABC'+(A'+B')''CD
ABC'+(AB)'CD
(AB)'CD + ABC'
aux truth table:
(AB)'CD ABC' ((AB)'CD + ABC')
0 0 0 see note 2
0 1 1 see note 1
1 0 1 see note 2
1 1 1 see note 1
note 1: If ABC' is true (mux select is 1) then output is true (mux's 1 input is set to 1)
note 2: If ABC' is false (mux select is 0) then output is (AB)'CD (mux's 0 input is set to (AB)'CD), the "see note 2" outputs are true only when (AB)'CD is true

Related

Renaming file based on a value in a tsv file

My input is a tsv file with 5 columns. It has the column names 'Position' 'A', 'B' and so on, that repeat every now and then in the tsv. How can I split this tsv file so that each one has one set of the column headers and the data underneth, but not the next set of column headers.
Input:
Position A B C D Seg2
1 9 0 0 0 0
2 0 0 16 0 0
3 0 19 0 0 0
4 0 0 18 0 0
Position A B C D Seg1
1 9 0 0 0 1
2 0 0 22 0 0
3 0 19 0 0 0
4 0 0 19 0 0
5 39 0 0 0 0
6 43 0 0 0 0
The ideal output would be the above in split into two tsv files, one named Seg1.tsv and the other Seg2.tsv.
What I have:
awk '/Position/{x="F"++i;}{print > x;}' file.tsv
How can I modify the above to rename the files?
You should just derive the filename from the last column :
awk '/Position/{x=$6".tsv"}{print > x;}' file.tsv

Bash: How to extract table-like structures from text file

I have a log file which contains some data and important table-like parts as following:
//Some data
--------------------------------------------------------------------------------
----- Output Table -----
--------------------------------------------------------------------------------
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
fooooooooo 0 0 3 0 0
boooooooooooooooooooooo 0 0 30 0 0
abv 0 0 16 0 0
bhbhbhbh 0 0 3 0 0
foooo 0 0 198 0 0
WARNING: Some message...
WARNING: Some message...
aaaaaaaaa 0 0 60 0 7
bbbbbbbb 0 0 48 0 7
ccccccc 0 0 45 0 7
rrrrrrr 0 0 50 0 7
abcabca 0 0 42 0 6
// Some data...
--------------------------------------------------------------------------------
----- Another Output Table -----
--------------------------------------------------------------------------------
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
$$foo12 0 0 3 0 0
$$foo12_720_720_14_2 0 0 30 0 0
I want to extract all that kind of tables from given file and save in separate files.
Notes:
A start of the table indicates a line which contains {NAME, Attr1, ..., Attr5} words.
WARNING messages may exist in the scope of a table and should be ignored.
Table ends when an empty line occurs and the next of that blank line is not a "WARNING" line.
So I expect the following 2 files as output:
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
fooooooooo 0 0 3 0 0
boooooooooooooooooooooo 0 0 30 0 0
abv 0 0 16 0 0
bhbhbhbh 0 0 3 0 0
foooo 0 0 198 0 0
aaaaaaaaa 0 0 60 0 7
bbbbbbbb 0 0 48 0 7
ccccccc 0 0 45 0 7
rrrrrrr 0 0 50 0 7
abcabca 0 0 42 0 6
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
$$foo12 0 0 3 0 0
$$foo12_720_720_14_2 0 0 30 0 0
I would write the following awk script by following your directions.
#! /usr/bin/awk -f
# start a table with a NAME line
/^ +NAME/ {
titles = $0
print
next
}
# don't print if not in table
! titles {
next
}
# blank line may mean end-of-table
/^$/ {
EOT = 1
next
}
# warning is not EOT
/^WARNING/ {
EOT = 0
next
}
# end of table means we're not in a table anymore, Toto
EOT {
titles = 0
EOT = 0
next
}
# print what's in the table
{ print }
Try this -
awk -F'[[:space:]]+' 'NF>6 || ($0 ~ /-/ && $0 !~ "Output") {print $0}' f
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
fooooooooo 0 0 3 0 0
boooooooooooooooooooooo 0 0 30 0 0
abv 0 0 16 0 0
bhbhbhbh 0 0 3 0 0
foooo 0 0 198 0 0
aaaaaaaaa 0 0 60 0 7
bbbbbbbb 0 0 48 0 7
ccccccc 0 0 45 0 7
rrrrrrr 0 0 50 0 7
abcabca 0 0 42 0 6
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
NAME Attr1 Attr2 Attr3 Attr4 Attr5
--------------------------------------------------------------------------------
$$foo12 0 0 3 0 0
$$foo12_720_720_14_2 0 0 30 0 0

full adder gate

I don't know if this question is considered to be related to stackoverflow (I'm sorry if it's not but I have searched and did not find an answer anywhere).
I have coded a full adder
Output:
Truth Table :
a1 a2 b1 b2 S1 S2 C
______________________________
0 0 0 0 0 0 0
0 0 0 1 0 1 0
0 0 1 0 1 0 0
0 0 1 1 1 1 0
0 1 0 0 0 1 0
0 1 0 1 0 0 1
0 1 1 0 1 1 0
0 1 1 1 1 0 1
1 0 0 0 1 0 0
1 0 0 1 1 1 0
1 0 1 0 0 1 0
1 0 1 1 0 0 1
1 1 0 0 1 1 0
1 1 0 1 1 0 1
1 1 1 0 0 0 1
1 1 1 1 0 1 1
If somebody has ever calculated this, can they tell me if my output is correct
a1 a2 b1 b2 S1 S2 C a b s c
______________________________
0 0 0 0 0 0 0 0 0 0 0 nothing plus nothing is nothing
0 0 0 1 0 1 0 0 2 2 0 nothing plus two is two
0 0 1 0 1 0 0 0 1 1 0 nothing plus one is one
0 0 1 1 1 1 0 0 3 3 0 nothing plus three is three
0 1 0 0 0 1 0 2 0 2 0 two plus nothing is two
0 1 0 1 0 0 1 2 2 0 1 two plus two is four (four not in 0-3)
0 1 1 0 1 1 0 2 1 3 0 two plus 1 is three
0 1 1 1 1 0 1 2 3 1 1 two plus three is five (one and four)
1 0 0 0 1 0 0 1 0 1 0 one plus nothing is one
1 0 0 1 1 1 0 1 2 3 0 one plus two is three
1 0 1 0 0 1 0 1 1 2 0 one plus one is two
1 0 1 1 0 0 1 1 3 0 1 one plus three is four
1 1 0 0 1 1 0 3 0 3 0 three plus nothing is three
1 1 0 1 1 0 1 3 2 1 1 three plus two is five (one and four)
1 1 1 0 0 0 1 3 1 0 1 three plus one is four
1 1 1 1 0 1 1 3 3 2 1 three plus three is 6 (two and four)
Looks right. Ordering your 16 rows a little differently would make them flow in a more logical order.
It's an adder! Just check if it's adding. Let's take this row:
a2 a1 b2 b1 C S2 S2
1 0 1 1 1 0 1
Here I have reordered the columns in an easier to read manner: higher order bits first.
The a input is 10 = 2 (base 10). The b input is 11 = 3 (base 10). The output is 101, which
is 5 (base 10). So this one is right: 2 + 3 == 5.
I'll let you check the other rows.

Text processing using bash

I have a vmstat dump file that has the header and values in this format
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
12 0 5924396 20810624 548548 935160 0 0 0 5 0 0 60 5 34 0 0
12 0 5924396 20768588 548548 935160 0 0 0 0 1045 1296 99 0 0 0 0
12 0 5924396 20768968 548548 935452 0 0 0 32 1025 1288 100 0 0 0 0
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
4 0 5924396 20768724 548552 935408 0 0 0 92 1093 1377 33 0 67 0 0
I'm writing a script in bash that extracts just the lines containing lines with numbers i.e. values and remove all lines containing the alphabet. How do I do that
If you need a lines with numbers and tabs\spaces only, grep -P "^[0-9\ \t]*$" should helps you.
$> cat ./text | grep -P "^[0-9\ \t]*$"
12 0 5924396 20810624 548548 935160 0 0 0 5 0 0 60 5 34 0 0
12 0 5924396 20768588 548548 935160 0 0 0 0 1045 1296 99 0 0 0 0
12 0 5924396 20768968 548548 935452 0 0 0 32 1025 1288 100 0 0 0 0
4 0 5924396 20768724 548552 935408 0 0 0 92 1093 1377 33 0 67 0 0
cat filename | grep "[0-9]"

Little Endian Bitmask

I need to convert an array of integers to a little endian bitmask using Ruby. Any links or hints would be appreciated.
the example says [2,7,9,11] => "4205"
a = [2,7,9,11] # 4205
b = [1,2,3,4] # 0F00
def array_to_mask(arr)
mask = 0
arr.each do |i|
mask = mask | (1 << i)
end
return mask.to_s(16)
end
p array_to_mask(a) # a84
p array_to_mask(b) # 1e
This does not work, but am i on the right track?
Can't you use arr.pack()? It has options for byte order.
Update: Ok I've taken a look at the documentation you mentioned and the only way I can make the example work is this:
7 2 11 9 (decimal index count)
0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 (bits)
4 2 0 5 (nibbles, in hex)
But that would mean that would mean that the 4205 are 4 nibbles that together represent 2 bytes? That is the only way I could make the first byte have the second and seventh bit set (reading little endian).
... This is more of an 'understanding the docs' issue than it it a ruby issue.
So the array solution is not the one you need, because you need to set the individual bits in a number. This is best achieved using (left) bit shift << and or'ing | the results together.
Enfora sent me a calculator which I examined to write a function. Hopefully this explanation will help whoever is next to try this.
values: [2,7,9,11]
Bits: | 8 7 6 5 | 4 3 2 1 | 16 15 14 13 | 12 11 10 9 |
Binary: | 0 1 0 0 | 0 0 1 0 | 0 0 0 0 | 0 1 0 1 |
Hex: | 4 | 2 | 0 | 5 |

Resources