Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def half_adder(i, j): sum = i ^ j carry = i & j return sum, carry def full_adder(i, j, k): sum, carry1 = half_adder(i, j)

def half_adder(i, j): sum = i ^ j carry = i & j return sum, carry

def full_adder(i, j, k): sum, carry1 = half_adder(i, j) sum, carry2 = half_adder(sum, k) carry = carry1 | carry2 return sum, carry

def parallel_adder(A, B, C, D, E, F): sum1, carry1 = full_adder(A, D, 0) sum2, carry2 = full_adder(B, E, carry1) sum3, carry3 = full_adder(C, F, carry2) return carry3, sum3, sum2, sum1

if __name__ == '__main__': print("Half-adder") print("i = 0 j = 0 | c = 0 s = 0") print("i = 0 j = 1 | c = 0 s = 1") print("i = 1 j = 0 | c = 0 s = 1") print("i = 1 j = 1 | c = 1 s = 0")

print("Full-adder") print("i = 0 j = 0 k = 0 | c = 0 s = 0") print("i = 0 j = 0 k = 1 | c = 0 s = 1") print("i = 0 j = 1 k = 0 | c = 0 s = 1") print("i = 0 j = 1 k = 1 | c = 1 s = 0") print("i = 1 j = 0 k = 0 | c = 0 s = 1") print("i = 1 j = 0 k = 1 | c = 1 s = 0") print("i = 1 j = 1 k = 0 | c = 1 s = 0") print("i = 1 j = 1 k = 1 | c = 1 s = 1")

A, B, C = 0, 1, 1 D, E, F = 1, 1, 0 W, X, Y, Z = parallel_adder(A, B, C, D, E, F) print() print(f"{A}{B}{C} + {D}{E}{F} = {W}{X}{Y}{Z}")

#output

Half-adder i = 0 j = 0 | c = 0 s = 0 i = 0 j = 1 | c = 0 s = 1 i = 1 j = 0 | c = 0 s = 1 i = 1 j = 1 | c = 1 s = 0 Full-adder i = 0 j = 0 k = 0 | c = 0 s = 0 i = 0 j = 0 k = 1 | c = 0 s = 1 i = 0 j = 1 k = 0 | c = 0 s = 1 i = 0 j = 1 k = 1 | c = 1 s = 0 i = 1 j = 0 k = 0 | c = 0 s = 1 i = 1 j = 0 k = 1 | c = 1 s = 0 i = 1 j = 1 k = 0 | c = 1 s = 0 i = 1 j = 1 k = 1 | c = 1 s = 1

011 + 110 = 1001

Explain every single step of this code clearly also talk about the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions