Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda