M G Harish

Thursday, February 15, 2007

Exploring new ways

If you have ever been to programming, you will surely have been asked to write a program to swap two numbers (If you haven't bothered about this simple program, you need not have to continue reading this article). Even if you are not well versed with the concept of programming, you will be able to solve this problem in one or the other way. Well, that's good. But I am trying to do much more than that, something that involves the combination of knowledge, thinking and understanding. I will go on describing about it in C language, since that's the language I like and that's the language I speak!!

Let's get down to the business here. If you ask anyone to swap two numbers, he might do it in this way:
temp = a;
a = b;
b = temp;

That's right. But it needs one more variable, temp. So, let us think and find some other way that needs no extra variable. If you know simple arithmetic, you might come up with this way:
a = a + b;
b = a - b;
a = a - b;

Let us see how the above code works.. For example, if a = 5, b = 7 then a = a + b; makes a = 12. The next statement b = a - b; makes b = 5 and the final statement a = a - b; makes a = 7. As we see, the values of a and b are interchanged. Our goal is achieved. Wow, the extra variable is eliminated! But there is one more concern here. It uses addition operations instead of mere assignments as in the previous case. Yeah, but what's the problem with that? you might ask. Well, there is, and you will notice it if you know how the microprocessors calculate. Addition is not a logical operation. It is an arithmetic operation. It is a combination of Exclusive OR (XOR) operation and AND operation. (Although ALUs of modern processors take care of this and do the operation in same amount of time as that needed for individual XOR or AND operations, I am not going to stop here, I'm here to explore new ways!). So, is there any way of still improving this? Yes, there is...

Now, if we can somehow eliminate this combinational operation of XOR and AND, we can achieve some more efficiency. For that one needs the knowledge of bitwise operations and obviously needs to know binary arithmetic. Assuming that you know it, here is the way:
a = a ^ b;
b = a ^ b;
a = a ^ b;

Going back to the same previous example of a = 5 (0101b), b = 7 (0111b) we get a = 2 (0010b) after the execution of the first statement. And after the second statement gets executed, we will have b = 5 (0101b) and after the execution of the third statement, we will finally have a = 7 (0111b) which is what we need.

Hmm, think it is the optimum, don't you? But I don't think so... If you know C, you will know that C provides shorthand operators. So, how about this:
a ^= b;
b ^= a;
a ^= b;

Well, now no one can further compress it. Eh, you think that? Remember, C provides the provision to put multiple assignments in a single statement and the operations are carried out from right to left. So, I come up with this, which is nothing but the merging of the above three statements, which I think, is the optimized one.
a ^= b ^= a ^= b;

If you find any piece of code that beats it, let me and the rest of the world know...

Friday, February 09, 2007

Aspired - Inspired - Expired

He was a boy of just seventeen years. Yet, he seemed to have got enough of his life. Out of frustration, he decided to commit suicide.

Sleeping pills and whisky make a deadly combination, he had heard. He worked in a drug house, where he stole some sleeping pills. He waited for a Saturday, for the home to be deserted. He was all set to go, go forever. The boy drank whisky and picked up the pills to take. At that time, his father who had forgotten something, and came back to the home. Loss of memory can, many times, be a boon and seeing this boy drinking, he asked what was going on...

The first reply was "Nothing", as expected. But when the father noticed the pills, there was no way to pretend. He said "I'm going to commit suicide". Well, some situations make you daring. The boy continued, "If you stop me today, I'll do it tomorrow". It is a tough time for a father, any father for that matter. What can he do now?

If the father was just like any other person, the story would have been different. But he wasn't like others. He called his son for a little walk, saying that the boy didn't seem to be in any urgency. That was true, for, the boy agreed to go for the walk. The father talked about many things, but none of them got the attention of the boy, until he said something about the boy's ambition to become a writer. Although it got the attention of the boy, it was a normal sentence, and he replied that it was a dream, which didn't come true. "That was yesterday". Father was very cautious, and asked "What about tomorrow?". The boy was puzzled. The father continued, setting up one of the best examples of inspiration... "You don't know what can happen tomorrow. Life is like a novel. Isn't it? It's filled with suspense. You have no idea what's going to happen until you turn the page". That's true, the boy thought. He had not seen the next pages of his life at all... There might be something wonderful happening tomorrow, he thought. And finally, the boy decided to postpone his suicide.

Does it seem to be a good fiction? Sorry, it is not a fiction. It is a biography. Story of one of the best modern English novelists. It is the biography of Sidney Sheldon, author of best selling books like If Tomorrow Comes, Master of the Game, The Other Side of Midnight, Rage of Angels etc.




The incident above took place in 1934, and Sidney Sheldon had to wait for many more years before becoming a famous writer. He started writing at the age of 50. He achieved what he wanted to be, and became a legendary writer.

Even though he is such a great writer, and almost all bibliophiles have read his novels, it is unfortunate that his death wasn't a big news at all. Yes, he passed away, on 30 of January 2007. I came to know about it after 4 days. An inspired soul, which had aspired to be a good writer, has expired on the same date as the other great soul Mahatma Gandhi was assassinated.

You can read the complete autobiography The Other Side of Me. And, if you are curious about every details of what happened on that day, you can just go through this exercept of his autobiography.

Friday, February 02, 2007

The fate of engineering: Jogi Remix

ಹೊಡಿ ಮಗ, ಹೊಡಿ ಮಗ, ಹೊಡಿ ಮಗ, ಹೊಡಿ ಮಗ, ಬಿಡಬೇಡ Copyನಾ...
ಅಕ್ಕ ಪಕ್ಕ ಮುಂದೆ ಹಿಂದೆ ಯಾರೆ ಸಿಗ್ಲಿ ನೀನು ಮಾತ್ರ ಬಿಡಬೇಡ Copyನಾ...
Engineering ಸೇರಿದ ಮೇಲೆ ಹೊಡೀಲೇ ಬೇಕೋ...
ಈ ಕೈಗೆ ಪೆನ್ನು ಸಿಕ್ಕಿದ ಮೇಲೆ ಬರೀಲೇ ಬೇಕೋ...
ಮಗ ಜೋರಾಗ್ ಬರೀಬೇಡ, Nervous ಆಗಬೇಡ
Bench ಅನ್ನು ಮುರೀಬೇಡ, ಬರ್ದು ಬೇಗ್ ಮುಗಿಸ್ಬೇಡ... ಲೇ
ಬಲವೀರ ರೆಡ್ಡಿ ಮುಂದೆ ಬಿಟ್ಟು Sketch ಹಾಕ್ತಾರೋ...
ಸ್ವಲ್ಪ ಕೂಡ ಯಾಮಾರಿದ್ರೆ Fail ಮಾಡ್ತಾರೋ...
ಬರಿ ಗೋಳು ಕಣೋ... ಇದು VTU ಕಣೋ...
Revaluation ಇಲ್ದಿದ್ರೆ ಸಾವೇ ಕಣೋ...


This is an SMS I got from one of my friends. I am in a dilemma here, whether to appreciate the creativity of the writer, or to commiserate him for being a VTU student.

This message not only exposes the condition of the VTU students, but also describes the wrong paths chosen by the students in order to survive. Hats off to the original author of this message!!

Friday, January 26, 2007

Orkut - Inside out

We have been orkutting for a long time now. But most of us do not know some of the features of orkut, and many of us do not bother about them either because we just scrap or send messages, and do nothing else. Orkut has some features which are unfamiliar to most of us. I will try to explore some of those now...
  • Just click the Media link at the top of the orkut page. It takes you to http://media.orkut.com/index.html where you can see a whole bunch of new links and information. It is somewhat like a blog directory. People post and discuss their thoughts, experiences and photographs. If you are interested, just try it once. You will get almost all kinds of information you need. Sky is the limit.

  • If you are a regular orkut user, and check all mails regularly, you must have been fed up with a spam mail asking you to forward that mail to all friends or else your account will be deleted. That's just a crap! Goto News link at the top of orkut page, which takes you to http://www.orkut.com/News.aspx where you can read about new features and recent advancements in orkut. Also notice the post named Is it true? Inactive accounts will be deleted? I have copied that here for some of you lazy fellows who still don't want to take the pain of going there and continue to spam...
    We heard there's a rumor going around orkut that says orkut.com will delete your account for inactivity. We've even received this notice from someone pretending to be Orkut himself! This is not true and you can safely disregard these messages or scraps.
  • If you have really gone to the News page, you will notice another link at the sidebar to the left, named Demographics. Just click that! You will be taken to http://www.orkut.com/MembersAll.aspx where you can see some graphical statistics about orkut. You will see Brazil is way ahead of other countries...

  • There are some less-known features like Hot list, Crush list, Ignore list, Teasers etc., which are explained in detail in Orkut help pages. However, this is the gist:
    If you happen to have your eye on another orkut member, here's how you can take action. Find their profile and click on the "personal" tab across from their name. From the left-hand side of the page, click the appropriate button to send them a teaser message or add them to your hot-list or crush-list.

    Your hot and crush lists allow you to flag an orkut member that has caught your attention. These lists are for your use only, and nothing happens when you add someone, with one exception. If you add an individual to your crush-list and that same person adds you to their crush-list, you will both be sent a message indicating that there's a match. The rest is up to you!

    You can block another user from sending you scraps, messages, invitations, and testimonials by adding that user to your ignore list. The ignore list is visible to you and other users will not know who is on your ignore list.
I will post many other tips and tricks of orkut whenever I see them... Till then, happy orkutting!!

Sunday, January 21, 2007

A trip with Hera Pheri

As the project fever began, we were seriously thinking of starting the project. So, we decided to go to Bangalore to get the required components. It was a mess right from beginning, as each of us (project-mates) were in different places and some of us were out of contact. Finally, after a lot of this and that, we settled onto the plan of going to Bangalore on 17th Jan 2007 morning, by intercity train.

We thought that it wasn't necessary for all of us to go, and hence V, who was in a far more distant place, didn't come. J planned to take off from Davanagere. C, who was in his village, came to my home the previous day and halted. Both of us planned to go from Harihar. We should be thankful to V2, who agreed to come with us to Bangalore to help us find the right areas to look at, as all of us were strangers in Bangalore. All went fine upto this, and only upto this...

The next day, we (I and C) had our breakfast in a hotel. In the mean time, V2 sent a message asking us whether to take train tickets or not. As we had much time, we said no. Then I realized that time was nearing, and I sent a message to V2 asking him to take three tickets. We finished our tiffin and headed towards the railway station.

V2 was waiting there. I asked him whether he took tickets. He said no (The message I had sent was not delivered yet). So I stood in the queue to take three tickets. S, who was also going to Bangalore for his project work, came to the station at the same time. So I had now four tickets to get, and I took them. All of us started chatting, waiting for the train to come.

I had the train tickets, and I asked them whether I shall keep them or someone else will take the responsibility. Only then, V2 told that he had his ticket. We had already started our day with a mess! We were four passengers from Harihar, and we had five tickets with us!! What to do now?! V2 and S came with an idea, and we asked J, who was yet to take the ticket in Davanagere, not to take the ticket. Thanks to the distance metrics, difference in charge to Bangalore from the two places was only 2 Rs...

During the same time, we met some other friends, who were going to Tumkur and Bangalore. Train arrived at about 8:25 AM to Harihar. After reaching Davanagere, J and some more friends also joined us. So we had nothing less to enjoy and we had a full compartment for ourself (Totally we were 10 friends). We spent most of our time chatting with each others, enjoying the best part of the day...

We had tiffin again in the train, after Arasikere. As we neared Bangalore, it was time for some FM stuff. Those who had FM radio enabled mobile phones were in two minds, whether to hear to it or save the battery!! With a little bit of music and a lot of chatting we reached Bangalore at about 1:50 PM. It was time to depart, and some of the friends headed to their destinations, and we headed towards the places where our destiny led us to...

We decided to have our food, and the roam around. While we were trying to find the place to go, a friend of C, R, came and joined us. We went to hotel Kamath and had our lunch. Then we came back to the city bus stand and took the daily pass, thinking that we have a lot to stray. But we were wrong, as we shall discover later...

We went to Sadar Patrappa (SP) Road. It is a street full of electronics shops. You can't even get water in there. We searched for the major component of our project, the Bluetooth module. We searched many shops, but in vain. The main purpose why we had gone to Banaglore, was not served. No shop in such a big city had a component we needed. I contacted BCS consultancy to query whether they had any Bluetooth kits which may be of use for us. But they told that it wasn't available in whole India itself, and the project we have undertaken is next to impossible one (I know it is an utter lie, but can't argue with them, eh?). V2 purchased some components he needed for their project and other purposes. Apart from that, it was entirely unworthy. For having come, we thought of purchasing any peripheral we needed. We searched for DVD writer in nearly 5 shops. All we could get was either a white LiteOn writer, or a black Sony or LG writer. I wanted a white LG or Sony writer. After a much exploration, we found a shop where they had a writer with replaceable front panel, and I purchased it. Then V2 I purchased a Bluetooth dongle each. (I needed it for project, and V2 for experiment). He also bought a 2 GB pen drive. Our next aim was to get the books of eight semester and hence we headed towards Avenue road...

Many of us, who were seeing it for the first time, were astonished by the number of second hand books available there. V2 was seriously indulged in getting the books. Rest of us spent much of our time seeing here and there, and sometimes towards the books. And finally after two hours, we went to Sapna Book House. We needed some reference books for our project. Closing time was 7:45 PM, after which no one is allowed to enter the shop and we went inside at about 7:35 PM. Fortunately we were able to find two books we needed and purchased them. Then it was time to decide where to go. All of us were in dilemma whether to stay there and search further in other places where we had left, or to come back. I thought it won't help to stay there and decided to come back. V2 was also of same opinion. J and C decided to stay there to meet their relatives. Both of them didn't know where to go, and it was already 8:30 PM!! J called his sister, and after a lot of thought, decided to come with us thinking that it would not be good to search the home in the night. So we were three now who settled to come back. C went with his friend to his room.

After having dinner, we three went to the bus stand. Since it was too early (we thought we get ended up in Davanagere at 4:30 AM if we leave Bangalore at 9:30 PM). I desired to have an ice cream (yeah, it is funny... but I myself am funny). Each of us had a pineapple flavoured softy. OMG! What a tasty one it was!! I wanted another one!! Both V2 and J refused to take another. So I alone ate the other one. But it was so tasty that I couldn't stop with two. (After all, you won't get it whenever you need, right?). So I decided to have one more. V2 seemed furious and headed towards the bus. I hurried to get the ice cream. When I came back, both of them had vanished!! I searched all around, and couldn't get a hint about where they had gone. Thank you mobile, I called J. I didn't call V2 because V1, twin brother of V2, was fed up having called V2 five times, without the calls being received. I don't think V2 is deaf either, not to hear the phone ringing. So V1 had called me twice instead. (Sometimes we can't tell why people use their gadgets, just for show off or for real use). J didn't receive the call, but came towards me seeing me. Couldn't the mobile operators wait? The call was being forwarded!! So I cut the call. And we met again.

We got on board of the bus. Aw! There was a smell of desi liquor!! Rules are meant to be broken. Liquors are meant to be drunk, no matter where and how. Unfortunately the bus was almost full and we got seat in the last but one row. V2 didn't seem to have noticed the fragrance!! (Did he have cold on that day? I don't think so... He hadn't refused first ice cream). I kept insisting to get down, but even some intelligent people act like silly at times. So, we didn't change the bus and continued the journey. The bus left Bangalore at 10:15 PM.

Both fortunes and hazards seem to strike in bursts. That person who was spreading the aroma was sitting just in front of us! So I and J started to contend for the window seat (V2, who is a third generation incarnation of Gandhiji, didn't bother about it at all). Then I and J had a agreement between us. I should sit there till Tumkur, and then we should interchange our position.

All of us took tickets to Davanagere, since I and V2 had student pass from Davanagere to Harihar. The journey wasn't bad, as we had all topics in the world to discuss about. J had a cat sleep in between, and was struggling to sleep properly. He didn't seem to have noticed Tumkur passing (Actually, none of us did, since the bus didn't go inside the city at all). At 12:20 AM it was time for the bus to stop for dinner!! (Some are weird, and some are more). There was some time, and we did what we needed to do. I got a biscuit pack, and V2 brought a chilling water bottle. (Where in the hell did he get the idea of getting cold water in that late night?!). But it was useful in a way, and the bottle was emptied in five minutes by three of us. By this time J had come to know that Tumkur had passed, and sat next to the window. (Thank God, that aromatic person was sleeping with his mouth shut, and there was no smell as such now). I and J started recalling the moments of our engineering life. V2 was sleeping. After Chitradurga passed, I and J got sleep. But V2 was awake by that time. Making all our calculations wrong, the bus arrived at Davanagere at 3:30 AM!! We distributed the books among ourselves, and waited for the bus to come. Both of us, I V2, were thinking whether student pass will be allowed at that time. We caught the bus at 4:00 AM. Unfortunately, we had to no place to sit other than the last seat. The bus was literally hopping, and we got free horse-like-ride!! Yes, free, because the pass was allowed...

Finally we reached Harihar at about 4:20 AM, and V2 took an auto and took all the books with him. I came to home, but and opened the gates in silence. I realized I was offline for too much time!! So I switched on my computer. But then I remembered the DVD writer and shut the computer down to put it. I had too many surprises to come along my way. The tray of the DVD writer was not opening at all. Cursing it, I went to bed, at 5:30 AM.

PS: The Hera Pheri hadn't ended yet, but the journey had. I will be jotting all of those shortly...

Sunday, January 14, 2007

Makara Jyothi

As usual, it happened again. The famous Makara Jyothi was observed on the day of Makara Sankranti. There are many legends as to why this light appears and there are many arguments telling that it is a hoax. Whatever it may be, but the light was seen on the eastern hills of Sabarimala (Kerala). It is truly amazing to see the light at the exact moment on that place.

The Makara Jyothi

Also it is interesting to know that a vulture flies over the sky, when the procession takes place

The vulture that flies over the procession

HAPPY MAKARA SANKRANTI

Saturday, January 13, 2007

Do you know about your system?

Sometimes ago, I came across a utility in Windows XP, which allows you to see many details about the system. This is systeminfo command, which is run in DOS window. It shows detail about Operating System, processor, network, hot fixes etc. It is a really a good utility that is not known to many people. It also gives information like when the operating system was installed, for how long has the system been on etc. To use this utility:
  1. Goto Start --> Run
  2. Type cmd /k systeminfo
  3. Click OK
Or, goto DOS, and just type the command systeminfo

[See the details of the command here]