January 3, 2013

[Algorithms by Robert Sedgewick] - Solution for problem 1.3.4

Given below is solution to problem 1.3.4 from Algorithms 4th Edition by Robert Sedgewick

1.3.4 Write a stack client Parentheses that reads in a text stream from standard input and uses a stack to determine whether its parentheses are properly balanced. For example, your program should print true for [()]{}{[()()]()} and false for [(]).



July 22, 2012

So why do we need Two's Complement ?

A simple question to ask anyone who is working or has studied in computer sciences but only few would be able to answer this. The whole idea of Binary representation is pretty simple and we all know how to represent unsigned bits.

In unsigned bit notation all the bits are part of a number. The number is always positive and a simple 8 bit number ranges from 0 (00000000) to 256(11111111).

Now to accomodate a negative number we have to some changes on how the Most Significant Bit or MSB (the one to the extreme left) is treated. If we consider setting MSB as 0 for positive numbers and 1 for negative numbers then 1 is 00000001 and -1 is 10000001.

Now this is where the requirement for two's complement came up.

If we go and add the numbers 1 and -1 in a traditional way we get

    0000 0001
 + 1000 0001
 ------------------
(1) 0000 0010
-------------------


The resulting number is (+)2 which is something we never expected. The need for Two's complement was to actually get 0 when you add -1 and 1. Getting two's complement of a negative binary number is pretty easy. 

One simple way is to invert all the digits if a given binary number and add 1 to it.
So for 1 ( 0000 0001), after inverting all digits it becomes 1111 1110. This after adding 1 becomes 1111 1111.

Lets add 1 and -1 in two's complement.

     0000 0001
+   1111 1111
-------------------
 (1) 0000 0000
-------------------

The result is 0 which is what's expected.

July 11, 2012

Identify the perfect color combination for your webpage


My work involves writing Java software on a daily basis. I occasionally work on web development as well. These days I am working on a small web application and wanted to quickly identify some colors which should be part of the multi - panel layout which I am designing. Doing color coordination is very important while designing a web site. Colors play a vital role in the website's reception. Any website with suitable color coordination is easy on the eyes and users love to spend time there

Colorschemedesigner.com is the best resource I have come across for identifying the different color which should be part of a web site. This website helped me in identifying basic 4 colors which are easy on the eye and for a great color co-ordination. On loading the web site we are presented with a smart interface which has a color palette displayed.


moving the cursor around color combinations can be updated. This can be done by moving around the hollow circle on the grid. Further the range of colors can also be increased upon by updating angle. This provides us with multiple choices of colors. If that's not all we can also see how the finished web page would look like by selecting Light/Dark page example. The sample page uses colors selected from  the palette and provide a decent example of a web page made out of colors selected. Highly recommended for all web developers.