Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Arithmetic representation of boolean logic

created by rep_movsd

(idea) by rep_movsd (2.6 d) (print)   ?   I like it! Sat May 29 2004 at 14:17:28

Introduction
Modern computers are constructed using digital logic circuits which allow linear analog electronic components like transistors and resistors to emulate boolean logic functions. The fundamental unit of a digital logic circuit is called a gate and all digital circuitry is built by interconnecting various gates.

Every basic gate has two inputs and one output, each of which can be in a high or low state ( i.e. voltage ). Each gate is defined by its truth table which is a list of outputs for each set of possible inputs. One exception is the NOT gate which has one input and one output.
If we represent a high state by one and a low state by zero, The possible inputs to a gate are 00, 01, 10, and 11. In the intersests of brevity, we can represent a gate by the output it produces for each of these inputs respectively.


The possible logical gates (which have names) are:
  • AND - 0001
  • OR - 0111
  • NAND - 1110 (Not AND)
  • NOR - 1000 (Not OR)
  • XOR - 0110 (Exclusive OR)
  • XNOR - 1001 (Not Excusive OR)
  • IMP - 1101 (Logical implication)
  • NOT - Outputs the inverse of its input.
  • It is provable ( and obvious ) that any set of outputs can be generated by a combination of AND, OR and NOT gates, or by a combination of NAND gates alone.


    Boolean logic representation of arithmetic operations:
    To perform arithmetic operations, the binary representations of the numbers involved is processed by an array of gates.
    For example, the operation of adding two binary digits has two inputs and two ouputs, with the following truth table.
    The outputs are the sum and carry bits (S and C )
              _______   
     _______ | A + B |  
    | A | B || S | C |  
    |---|---||---|---|  
    | 0 | 0 || 0 | 0 |  
    | 0 | 1 || 1 | 0 |  
    | 1 | 0 || 1 | 0 |  
    | 1 | 1 || 0 | 1 |  
     ----------------   
    It is clear that the sum bit is A XOR B and the carry bit A AND B.
    A circuit consisting of an AND gate and XOR gate with their inputs wired in parallel thus adds binary digits together and is called a half adder. Similarly, all arithmetic operations can be carried out by manipulating the bits using logic gates.

    Now we are ready for :-


    Arithmetic representation of boolean logic
    While idly pondering the above (Boolean logic representation of arithmetic operations) , I realized that the converse was also possible.
    If we restrict our inputs to 1 and 0, we have:
  • A AND B = A * B
  • A OR B = A + B - ( A * B )
  • A XOR B = A + B - ( 2 * A * B )
  • NOT A = 1 - A
  • In C++ code you could write:
    bool AndFn( bool a, bool b ) { return bool( int(a) * int(b) ); }
    bool OrFn( bool a, bool b ) { return bool( int(a) + int(b) - int(a) * int(b) ); }
    bool XorFn( bool a, bool b ) { return bool( int(a) + int(b) - 2 * int(a) * int(b) ); }
    bool NotFn( bool a ) { return bool( 1 - int(a) ); }
    
    So it is possible to represent any boolean expression as an arithmetic one.

    printable version
    chaos

    binary propositional calculus skolemization D-Day
    The Atlantic Wall transistor predicate calculus ssh
    1900 resistor South African Shopping malls logic
    semimajor axis and semiminor axis South African Weather
    Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
      Epicenter
    Login
    Password

    password reminder
    register

    Everything2 Help

    Cool Staff Picks
    Things you could have written:
    A Computer Prayer
    Salt
    Joan of Arc
    Mount Stromlo Observatory
    Theo Van Gogh
    vegans beware
    Gone beyond reasonable
    12 Monkeys
    Nazca Lines
    Cambrian Explosion
    Robert Rodriguez
    summer solstice
    The Seven Chakras
    New Writeups
    lismaraxt
    Ice Theory of The Origin of Life(idea)
    allthetime
    Apple Cinnamon Suicide(idea)
    Lucy-S
    shovelglove(idea)
    Adaptive Child
    Mexican secret sauce(recipe)
    Adaptive Child
    nacho libre(recipe)
    TheLady
    Iron Man(review)
    Scaevola
    Risk in the Roman law of sale(idea)
    semicolon
    overheard at IHOP(event)
    choirotey
    Violent pickup lines(idea)
    Ouzo
    Blue Ovaries, Grrrrrrwl(log)
    uncljoedoc
    explanation(person)
    Noung
    One no longer loves one's insight when one communicates it(idea)
    AspieDad
    Pornology(essay)
    nailbiter
    Nicole duFresne(person)
    Simulacron3
    stigmergy(idea)
    Everything 2 is brought to you by the letter C and The Everything Development Company