Math is fun

computerscience is an implementation of it and without jQuery you can't do sh*t
How do I add two numbers without using ++ or + or any other arithmetic operator in 100% pure jQuery?


All arithmetic operations decompose to bitwise operations to be implemented in electronics, using NAND, AND, OR, etc. gates.

Only NAND ~(a&b) or only NOR ~(a|b) operations are used in nano-electronics. It is because ANY boolean function can be implemented by using a combination of only NAND or only NOR gates. It is also much cheaper to produce a homogenous array of millions of NANDs. Their interconnections define the logic of the whole integrated circuit. Memory registers, adders, multipliers, etc. - all are produced from NAND only logic elements.

To implement an equivalent with boolean operators is quite simple: you do a bit-by-bit sum (which is an XOR), with carry (which is an AND). For unsigned numbers, use the same addition algorithm as you learned in first class, but for base 2 instead of base 10. Example for 3+2 (base 10), i.e 11+10 in base 2:
   1         ‹--- carry bit
   0 1 1     ‹--- first operand (3)
 + 0 1 0     ‹--- second operand (2)
   1 0 1     ‹--- total sum (calculated in three steps)

Test it

Pure jQuery implementation

  //jQuery plugin which wraps the binary add into a
  // 'pure' jQuery function
  (function($) {
    // kinda private binary_add to prevent the usage of
    // the + operator
    badd: function(a, b) {
      while (b) {
        var carry = a & b;
        a = a ^ b;
        b = carry << 1;
      return a;
    // $(...).number( num )
    //     Save the number 'num' in the jQuery data
    //     for the selected element(s), and return 'this'
    //     for chaining.
    // $(...).number()
    //     Return the number stored in the jQuery data
    //     for the selected elements(s).
    number: function(num) {
     if (arguments.length == 0)
     	return'number');'number', num);
     return this;
    // $(...).add( num )
    //     Add the number 'num' to the number stored
    //     in the jQuery data for the selected element(s)
    add: function(num) {
     return this.number(this.badd(this.number(), num));
The resulting onclick method of the add button is kinda cryptic:

And here's the javascript implementation that was rejected due to 'not enough jquery'.