Archive for February, 2007

The NUXI problem

Before we get into any details I think it’s worth a discussion what exactly is the difference between ‘Data’ and ‘Data representation’ in computer. When you see the representation ‘10′ you understand that it represent count ten. When you see the roman letter ‘X’ then also you interpret it as count 10.So ‘10′ and ‘X’ are data representation of same thing - count 10.In the world of computers also they have their own data representation, i.e. binary format. The count ten can be represented using  1 byte-00001010,which the computer recognizes as count 10 every time it sees this bit pattern.

There is no problem when reading a single byte because all computers read the bit patterns the same way. But not all the data representation can be done using 1 byte. Take for example a short variable form C/C++. It requires 2 bytes to represent one short variable.

Now the problems starts - when you read multi-byte data, where does the biggest byte appear?
•Big endian machine: Stores data big-end first. When looking at multiple bytes, the first byte (lowest address) is the biggest.
•Little endian machine: Stores data little-end first. When looking at multiple bytes, the first byte is smallest.

Like the decimal ‘10′ and roman ‘X’ represent the same thing, the Big and Small endian representations represent the same data but with different bit patterns and this creates problem when transmitting data between machines which has different byte-sex.

Let’s illustrate it with an example where we try to store the word UNIX in two consecutive short variables

short *s;    // pointer to set shorts
s = 0;        // point to location 0
*s = UN;  // store first short: U * 256 + N
s = 2;       // point to next location
*s = IX;   // store second short: I * 256 + X
On a big endian machine we see
Byte:     U N I X
Location: 0 1 2 3

On a little-endian machine we would see:
Byte:     N U X I
Location: 0 1 2 3

In the second case even though the bytes are stored “backwards” in memory, the little-endian machine knows it is little endian, and interprets them correctly when reading the values. But what happens when u pass a data from little-endian machine to big endian machine. The big endian machine reads UNIX as NUXI and that may be the beginning of a big problem .And this exactly is called the NUXI problem.

And the solutions:-

•The easiest approach is to agree to a common format for sending data over the network. The standard network order is actually big-endian.
•The other approach is to include a Byte Order Mark (BOM) before every piece of data which is sent across the network
 

‘Cuppycake’ - The cutest song available :)

One of the cutest songs that I have ever heard. Thought it’s worth a pick to share with you all. If you haven’t heard it yet, download (330KB) it for yourself and enjoy. Take my word; it’s worth wasting your bandwidth.

 Song Name: Cuppycake
Lyrics & Music :Judianna Castle
Artist: Strawberry Shortcake
Album: Unknown
Year: 2004
Lyrics:-
You’re my Honeybunch, Sugarplum
Pumpy-umpy-umpkin, You’re my Sweetie Pie
You’re my Cuppycake, Gumdrop
Snoogums-Boogums, You’re the Apple of my Eye
And I love you so and I want you to know
That I’ll always be right here
And I love to sing sweet songs to you
Because you are so dear 

“I wrote this song about all of the sweet names my mom and dad called me when I was little and all of the sweet names that I call my daughter Amy.I entitled it “You’re My Honeybunch” and gave it to her as a Valentine’s day present.” - Judianna Castle

What the world may come to

What the world might look like in a couple of million years ahead? Any wild guesses? Definitely not a sphere….but a tetrahedron! This was published in an article in ‘My Magazine’ dated May 1918.The explanations state that the earth surface has already hardened to the max, so the total surface area will remain constant. But the crust is cooling up which is gradually shrinking in volume. But it adapts itself to the shrinking interior by taking a shape which occupies least volume. So the earth is to become a tetrahedron, a sort of pyramid, the shape which gives the smallest bulk for its surface. So in next rebirth (if not born as a mole) you very well could be studying a world map similar to this…

World

3 ways to swap variables without temp variable

I bet this question has been asked more than a trillion times in the history of technical interviews and it sounds…..”How to swap variable values with out using a temporary variable?”..as simple as that…ooch…but how?

The most obvious way of doing a swap is by declaring a temp variable

             temp = I;

                   I = J;

                   J = temp;

But when you say no additional variables to be used, you can always use this age old trick           

                  i =  i  + j;

                  j =  i  -  j;

                  i =  i  -  j;

This has more flavors to follow like, using * / combination instead of +  -

                  i  =  i  *  j;

                  j =  i   /  j;

                  i =  i   /  j;

And the good news is that, the best of all is yet to come…. the XOR trick

                 i  =  i  ^  j ;

                 j   i   j;

                 i   i  ^  j;

This one works just fine and is the perfect one suited for any primitive variable types.

So next time some one gives you an intelligent look after this question…don’t forget to prick his ego.

AMD Crop Circles

Advanced Micro Devices Released its 64-bit micro processor and they did have a different promotion plan before their grand launch. They hired a group of crop-circle experts to create circles throughout UK and America. As it was late September the usual canvas of wheat and barley fields where harvested, so they had to compromise with tidal beach sand on grass…..and just take a look at how this 300ft wide-200ft tall monster look like.

AMD Crop Circles


 

February 2007
S M T W T F S
« Jan   Mar »
 123
45678910
11121314151617
18192021222324
25262728  

Categories

Blog Stats

  • 29,660 hits

Last 100 Visitors

Map IP Address

Map IP Address