Sunday, November 15, 2015

Number of lines of code

I was asked to find out the number of lines of code in our entire module so as to figure out how hard is to maintain it. Here is the source to find out the number of lines in a python project


Wednesday, November 4, 2015

Finding out the system is little endian or big endian system

Here first a value 1 is stored in a int variable. Address of that variable is taken and cast as a char address which will work only on the first byte of the word. If a value one is available in the char then its little endian system otherwise its big endian

Sunday, August 23, 2015

Decorator implementation in python




The decorator implementation in python is helpful while implementing add on to a particular class functionality. Here in the below example the html bold and italic properties are added to a string using the decorator implementation.




Tuesday, May 5, 2015

Subtract two numbers using bit manipulation

Subtracting numbers is done similar to add number(refer previous post in this blog) with minor difference. Instead of direct and between x and y . We take negation of x to and.

Adding two numbers using bit manipulation

Adding of two numbers can be done with bit manipulation. The operation if we examine atomically mirrors the actual operation we do while adding two numbers. Here is sample code:

Thursday, March 12, 2015

Swapping bits of an Integer

Swapping individual bits is implemented using a function. This function is repeatedly called with different position data.

Wednesday, March 11, 2015

Printing the binary format of a integer

Here printing iss done thru a neat macro trick. We can calculate different way too, which is commonly seen. In that case we divide the number by 2 and not the modulo and append it to a string. Same time we will divide the number by two and make it as the new number. This process continues till the number becomes equivalent to one.

Saturday, January 31, 2015

Printing powerset for given set of characters.

Printing powerset of characters is somewhat easy. Here the key point is to understand that for a given number of n characters we will have (2^N)-1 combinations. We will then count thru integers starting from 1 to (2^N)-1 and then check the bit set on the integer and accordingly the same element will be printed from the character array. Below is the C implementation of this interesting program :

Sunday, January 25, 2015

Stack implementation in C language.

Given below is a simple stack implementation in C language. Three main functions of a stack are implemented here, namely push, pop and top.

Tuesday, January 6, 2015

String compression

Given a string with repeated characters find out a way to compress the string with a count of number of times the character got appended. For example a string like "aabbbccdeeefff" would become like "a2b3c2de3f3" after compression !