Question: Write a SCHEME procedure called (add-binary x y) that adds two binary numbers represented as a list of 0s & 1s. For example: (add-binary (1
Write a SCHEME procedure called (add-binary x y) that adds two binary numbers represented as a list of 0s & 1s. For example: (add-binary (1 0 0) (1 0)) ? (1 1 0)
I was able to write the function to to add the two numbers together:
(define add-binary (lambda (x y) (cond ((null? x) y) ((null? y) x) (else (cons (+ (car x) (car y)) (add-binary (cdr x) (cdr y)))))))
Now I just need help with the helper function to deal with the carry for binary addition and it needs to have one more parameter for the carry:
(define binary-carry (lambda (x y carry)
Any help is much appreciated!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
