Embercode
✕
How Computers WorkQuick quiz

Gates and adders

8 questions. Covers Building a tiny adder.

Questions 1 to 5 of 8

  1. 1. What does this code print? ``python def XOR(a, b): return a ^ b print([XOR(a, b) for a in (0, 1) for b in (0, 1)]) ``
  2. 2. What does print(full_adder(1, 0, 1)) print? The gate functions are the same as in the lesson: ``python def XOR(a, b): return a ^ b def AND(a, b): return a & b def OR(a, b): return a | b def half_adder(a, b): return XOR(a, b), AND(a, b) def full_adder(a, b, carry_in): first_sum, first_carry = half_adder(a, b) second_sum, second_carry = half_adder(first_sum, carry_in) return second_sum, OR(first_carry, second_carry) ``
  3. 3. What does this code print? ``python print(2 and 1, 2 & 1) ``
  4. 4. Put the steps of one full adder in the order the circuit runs them.

    Use the arrows to put the steps in order.

    1. 1.Feed s1 and the carry in into the second half adder, which gives the sum bit and the carry c2
    2. 2.OR the two carries, c1 and c2, to get the carry out
    3. 3.Pass the carry out to the column on the left as its carry in
    4. 4.Feed a and b into the first half adder, which gives the partial sum s1 and the carry c1
  5. 5. The 4-bit adder adds 9 + 9. The low four sum bits read 2, and the carry out is 1. What is the true sum?

4 question(s) left on this page.