Monday, June 20, 2011

Big Endian and Little Endian


  • What is the difference between big endian and little endin machines

The data ordering at the memory is different for them, in little endian higher address have the most significant byte and lower have the least signifincant byte. and otherway round in case of big endian machines.

  • How do u determine a processor to be little endian or big endian, write a small program for it.

int a = 1;
if( *((char *)&a) == 1) 
    printf("Little endian");
else
    printf("Big Endian");


This can also be done using an eum as shown below


enum
{ 
  int a;
  char c[4];
}

a = 1;
if(char[1] == 1) 
    printf("Little Endian");
else
    printf("Big Endian");

Thursday, June 9, 2011

Traverse a tree without recursion

The basic problem of traversing a tree requires recursion. If you dont have recursion then you should have a mechanism to save either side of the tree on to a temporary location, this can be done with a stack.
So the algorithm should be

1) traverse the node, if there is right push on to stack, and go to left node
2) if there is no left then pop from the stack and go to that node.
3) do this til all the nodes are exhausted. i.e. till your node pointer is null

Find the code here, for your reference. Push and Pop can be implemented as a simple stack methods.

/* Traverse a tree without recursion */
/* The basic idea is to use a stack for storing the other side of the tree when going in one direction */

void traverse_without_recursion(node *head) {
    node *next = head;
    while(next != NULL) {
        printf("%d", next->data);
        if(next->right)
            PUSH((int)(next->right));
        if(next->left)
            next = next->left;
        else next = (node *) POP();
    }
}

Write a program to find the max and second max


This is little tricky, but not difficult. easiest way to do this is to sort the array and then find the answer. But that not expected out of you.

The algorithm here is take thefirst element as the max and second max. Then loop through all elements

  1. If the number is larger than max then make it max, and make old max to second max.
  2. Else if it is more than second max then make it the second max.
  3. In all other cases drop that number
Here goes the code for your reference.

/*
** Write a program for finding the max and second max 
** of an array of given size */

#define SIZE 10

int main(void)
{
    int array[SIZE] = {10, 5, 16, 2, 1, 2, 3, 18, 21, 4};
    int i, max, sec_max;

    max  = sec_max = array[0];

    for(i=0; i< SIZE; i++)
    {
        if(array[i] > max) {
            sec_max = max;
            max = array[i];
        }
        else if(array[i] > sec_max)
            sec_max = array[i];
    }

    printf("max =  %d, sec max = %d", max, sec_max);
}

Saturday, June 4, 2011

Error message when you click a hyperlink in Outlook

Today morning, When I open my outlook for joining a meeting, I was not able to click the link for meeting, it was working when I pasted the same on browser,  When you click a hyper link in Microsoft Outlook, you may receive the following error message: "This operation has been cancelled due to restrictions in effect on this computer. Please contact your system administrator." I was clueless as everything was working fine a day before. Did some search on google and found that microsoft has published a solution for the same.

This was said to be a problem due to some corrupted registry keys after the internet explorer upgrade, and there is patch executable released by microsoft which would fix the problem for you, check this link

If you find any issues after this, do let me now :)

Wednesday, June 1, 2011

Fix for Scroll Issue with Picasa 3.8 on Windows 7

Recently I faced a strange issue with picasa, the photo organizer/editor from Google. The scroll does not work !!, It was working perfectly fine on my personal laptop, but was not working on my office laptop, and scroll works fine in rest of the applications. I was thinking there is something to do with the installation, but reinstall also did not solve the problem,

Later I found that, Most (almost all) mouse drivers cause mouse wheel events with a "delta" of ±120. This is an arbitrary value that has been choosen by Microsoft in the past to allow finer control.

Since then, several programs use that value directly to test whether the mouse has been scrolled down or up (delta / 120 == 1 -> down, delta / 120 == -1 -> up, or something like that).

However, the Intellipoint software causes mouse wheel events with smaller "delta" value (the expected finer grain control), and programs which use the 120 value that way just fail to register the wheel movement, because in integral values, 30 / 120 = 0...

Let's hope Picasa developers would fix this issue soon, by modifying the mouse wheel handling method.

There are ways you can fix this issue temporarily, one is by using the Autohotkey. Autohotkey is a program you run in the background, which loads simple or complex scripts controlling the mouse and keyboard inputs, as well as other wanted behaviors in your Windows system. You can intercept the mouse wheel event and change the delta value before passing to a particular program, so if you make it 120 again, you would solve the issue.
  1. Download and install AutoHotkey (http://www.autohotkey.com)
  2. Right-click an empty spot on your desktop or in a folder of your choice.
  3. In the menu that appears, select New -> AutoHotkey Script. (Alternatively, select New -> Text Document.)
  4. Type a name for the file, ensuring that it ends in .ahk. For example: Test.ahk
  5. Right-click the file and choose Edit Script.

In the window that appears (likely Notepad), copy the lines of the script above. Save your document.

AutoHotkey does not run by itself, it runs a script. So you need to put the script file you just created in Startup, and it will start automatically when Windows start. This should fix your mousewheel problems with Picasa.

I have found that the latest IntelliPoint 8.0 software (released August 2010) fixes the scrolling issue. It also does the same thing, it detects that the picasa is running and changes the delta value to 120 and things would work just perfct

You can download the latest version of Intellipoint software for your mouse from here,