Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda