Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN SOMEONE PLEASE CORRECT MY CODE TO OUTPUT THE CORRECT ANSWER BELOW: (define (NOT-gate a)(if (= a 0) 1 0) ) (define (AND-gate a b)

CAN SOMEONE PLEASE CORRECT MY CODE TO OUTPUT THE CORRECT ANSWER BELOW:

(define (NOT-gate a)(if (= a 0) 1 0) )

(define (AND-gate a b) (if (and (= a 1) (= b 1)) 1 0 ) )

(define (OR-gate a b) (if (and (= a 0) (= b 0)) 0 1) )

(define (XOR-gate a b) (define (XOR-gate a b) (if (= a b) 0 1))

(define (half-adder x a b) (XOR-gate x (XOR-gate a b))) (define (carry-out x a b) (OR-gate (AND-gate x (OR-gate a b)) (AND-gate a b))) (define (full-adder x a b) (cons (half-adder x a b) (carry-out x a b)))

(define (tail lst) (if (null? (cdr lst)) (car lst) (tail (cdr lst)))) (define (rmtail lst) (if (null? (cdr lst)) '() (cons (car lst) (rmtail (cdr lst)))))

(define (formatResult lst) (if (= (length lst) 1) (list lst) (append (formatResult (rmtail lst)) (list (tail lst)) ))) (define (n-bit-adder A B n) (if (= (length A) (length B)) (recursiveAdd A B 0)) ) (define (recursiveAdd A B c) (if (null? A) (list c) (append (recursiveAdd (rmtail A) (rmtail B) (cdr (full-adder (tail A) (tail B) c))) (list (car (full-adder (tail A) (tail B) c))))))

;Test cases (define x1 '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) ) (define x2 '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) ) (define x3 '(0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1) ) (define x4 '(1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0) ) (define x5 '(1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1) ) (define x6 '(1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 0) )

(display "n-bit-adder Output ") (n-bit-adder x1 x2 32) (n-bit-adder x3 x4 32) (n-bit-adder x5 x6 32) (n-bit-adder x2 x3 32) (n-bit-adder x4 x5 32) (n-bit-adder x1 x6 32)

; Expected outputs ;(0 (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)) ;(0 (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)) ;(1 (1 0 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 1)) ;(1 (0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0)) ;(1 (1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1)) ;(0 (1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 0))

;MY OUTPUT

image text in transcribed

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions