Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following function using the Scheme programming language: A function (

ID: 3844093 • Letter: W

Question

Write the following function using the Scheme programming language:

A function (addBinary binaryList) that takes a list of binary numbers and returns their decimal sum. (addBinary '(1101 111 10 101)) returns 27.

The function must be written in a functional style and must use only the basic Scheme functions car, cdr, cons, null, atom, the equality functions, the arithmetic functions, append, and the conditional functions if and cond. Be sure to write some code to demonstrate your function on various inputs.

Explanation / Answer

Answer

Below is the required code in scheme programing language

#lang racket
(define (bin->Dec variable1)
(cond [(zero? variable1) 0]
[else (+ ( * 2 (bin->Dec (quotient variable1 10)))
(remainder variable1 10))]
))
(define (addBinary binaryList)
(cond [(null? binaryList) 0]
[else
(+ (bin->Dec (car binaryList))
(addBinary (cdr binaryList)))]))