Wednesday, January 15, 2014

Javascript big int operation

Javascript int are actually float. When '&' bit-wise AND is used, the value is converted to integer and operated on. It's 32 bits only, and is signed by default. So for big int longer than this, there is no way to do bit-wise AND.

Here is a solution: first convert the input integer string (a string, not a int) into binary format, then do a bit by bit comparison. Code is below.

function BIGINT_AND(a, b) {
  a = toBinary(a);
  b = toBinary(b);

  for (var i = a.length - 1, j = b.length - 1; i >= 0 && j >= 0; -- i, -- j) {
    if (a[i] == 1 && b[j] == 1) return 1;
  }

  return 0;
}

// convert from decimal format to binary format
function toBinary(decNum){
    return parseInt(decNum,10).toString(2);
}

Monday, January 13, 2014

Java web development review

Just want to review some basic java web development technologies, such as JSP, JSTL and servlets.

Online search on topic "JSP Tutorial" 

Below tutorials are listed in the order of from simple to more complex:

JSP Tutorial - very very basic tutorial
Tutorials Point: Basic JSP Tutorial - a little more detailed
Servlet
 
Building Web Apps in Java: Beginning & Intermediate Servlet & JSP Tutorials
The Java EE 5 tutorial





Blog Archive

Followers