Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Binary Subtraction using logic gates

I've been trying to recreate a binary full subtractor from a logic circuit diagram, but I can't seem to get a output that is accurate. I've rewritten it a few ways and ran it without a loop and expressing the logic differently. Looking at some examples I really don't see what is wrong. The idea is to get 2 n digit numbers as input and mask each bit then preform the subtraction logic. I have a working adder that I could reuse by inverting the second value, but I'm doing this for educational purposes to familiarize myself with the logic of ALUs.

class Alu {
  constructor(b = 8) {
    this.bits = b;
  }
  sub(y, z) {
    let m = 1; //mask
    let d = 0; //diff
    let b = 0; //borrow
    let w = 10; //base
    for (let i = 0; i < this.bits; i++) {
      let yM = y & m;
      let zM = z & m;
      d |= b ^ (yM ^ zM);
      b = (~yM & zM) | (~yM & b) | (~zM & b);
      m <<= 1;
    }
    console.log(y.toString(w));
    console.log(z.toString(w));
    console.log(d.toString(w));
  }
}

Here are the reference images I'm using:

Full Subtractor Logic Circuit

4 Bit Subtractor

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!