Monday, May 21, 2007

To be (signed) or NOT To be (signed!)

A few days back, we observed an interesting behavior of signed and unsigned chars.
We had an array and were using a char variable with right shift operation as subscript in order to access a member in the array. (something like foo[foobar >> 4])

I was surprized to see that for some reason, after the shifting operation, the subscript value came out to be negative. wheras (unsigned char)fobar >> 4 was giving a positive value.

I just could not digest the behavior. My argument was that memory location allocated to hold the value of foobar will have some bit pattern. I don't care what it is. When I right shift this bit pattern, it should just shift and the resultant bit pattern should be THE SAME irrespective of whether foobar is signed or unsigned.

But then it hit me. In case of signed data, the MSB is the sign bit. It does not form part of data. So when I right shift a signed data, the MSB will not move. Whereas, in case of unsigned data, Thus, if I right shift a negative number, the resultant will also be negative. And that is indeed correct, as right shifting is equivalent to division by 2.

And the subscript on an array is always treated as signed value.

So, signed and unsigned makes difference! Recall the basics :-)

Saturday, May 19, 2007

Mahabaleshwar

With a lot of excitement and enthusiasm we started our journey to Mahabaleshwar. The plan was simple ... Go there ... Look for some decent accommodation ... If you get one, spend the weekend and return ... else just return home before its dark!
After a 3hrs of drive filled with thrill, excitement etc. we reached Mahabaleshwar. As we had already expected, there was a lot of rush. After all this is the peak season.

We first went to a resort "Ramsukh" ( a friend who had stayed here earlier referred this resort to us). We went to the reception to enquire about a room. I still cant believe what I heard ... "Sir, we have only one cottage available. The rest of the resort is full. For one night stay, the cottage will cost you Rs ..... 17,000/- ONLY!" My God! This is the highest price I have heard till date for one night accommodation. A similar accommodation with similar amenities 'in Singapore' will cost you some 7000/- (INR). I was further shocked to know that 3 out of such 4 cottages were already taken up. Meaning there are people on this planet who believe that the accommodation is worth the price!!! May god help them make sound decisions :-P. Well, we obviously decided to try other hotels/resorts. But before that we decided to check out a famous 'SPOT' in Mahabaleshwar ... Arthur's Seat. The route to Arthur's Seat is really nice ... its as good as a switchback ('Ghaat' as it is called in local language), with dense plantation on both the side and many many blind turns! The climate was good, cooler that Pune. (But the Sun on the top didn't spare us :-( ).

We had a GREAT time at 'Arthur's Seat' spot. We bought some 'Baraf ka gola', some local fruits (ever heard of a small black fruit called 'Tuti' ?). We found a person who would sell you your 'One minute photo' (Now we have one memorable photo of this trip!) The funny thing was that this fellow wont let you stand where YOU wish to stand. It is him to decide which is the best place for a 'Couple Snap' and which is the best place for a 'Family Snap' :-)

After spending time at Arthur's Seat, we returned back to the main Mahabaleshwar city. We didn't find a single hotel who would offer accommodation for some 2000/- All of the hotels had 'Exactly one room available' which would cost some 4000/- bucks. We had a look at the rooms, and concluded that it was definitely not worth the price. Secondly, we were not sure of what to do even if we get an accommodation. I mean, we didn't find anything special as such at Mahabaleshwar :-( So, the plan was SEALED. We were not staying at Mahabaleshwar. So, after lunch, we started back at around 3.15 in the afternoon.

On our way back, we spent almost an hour at Mapro Garden. This is a great place to hang around. Lot of trees, lot of flowers, great sandwich and ice-cream .... its just great.

We left Mapro Garden by 4.15, and reached home in less than 2.5 hours!

So ... here is the conclusive part ....
Except natural beauty, there is nothing in Mahabaleshwar. It is no more a hill station one would like to visit in Summer. Reason is simple ... its not cool anymore, and even if the air is cool, the sun on the top doesn't spare you :-(, the places is crowded, and the accommodation will cost almost 3 times the off season rate.
In my opinion, winter is the best time to visit this place. You will have a pleasant gift left behind by the rains ... greenery! the climate will be really cool and you will surely enjoy walking on the streets even in the afternoon. you will get good accommodation at very cheap price. Thirdly, it will not be crowded at all.

If you have a group of friends .... you can also plan a one day trip to Mapro Garden. I mean, JUST Mapro garden. No need at all to spend efforts,fuel,time going all the way to Mahabaleshwar. Just go to Mapro, spend time there, have food, ice-cream, juices ... and come back!

Planning for Mahabaleshwar

Finally, a plan that was on paper for quite some time, was executed today.
I and Swati were planning a trip to Mahabaleshwar for almost a month. But for some reason or the other, it would not materialize. But today, finally, we made it to Mahabaleshwar :-)

We returned to Pune from Nashik on 14th. We knew that we have one weekend in hand, before our next trip to Nashik. And then we decided to go to Mahabaleshwar on this weekend. Why mahabaleshwar? well, actually there is nothing special about this place (not atleast for us!). We just wanted to go to some place near (?) Pune, on bike! So the options were ...
1) Some Ganapati mandir (Astavinayak mandir).
2) Lonawala / Khandala
3) Matheran
4) Panchgani / Mahabaleshwar

Now Ashtavinayak were ruled out, as it would have been (strictly) a few hours trip. We wanted to spend the weekend at some place (at least one complete day). Now out of the remaining options, Matheran was ruled out, as one can not take vehicles up there. You have to park then somewhere (no idea where) and the walk to the main city. So 'I' canceled the idea. I have been to Lonawala, and I just cant think 'what a person can do in Lonawala in summer?'. I believe Lonawala/Khandala are places to be visited only during and immediately after monsoon. So we were left with only one option.

Panchgani / Mahabaleshwar was a considerable option.
The reasons ...
1) The place(s) is at a drivable distance from Pune. (120km - approx. 3 hrs drive)
2) The place(s) is known as a 'Hill station'. A perfect place to visit in Summer?

So ... the plan was fixed, the tank was filled full, the bags packed, alarm set and we went to bed dreaming about tomorrows drive.

To be frank, I was a little nervous. I have been doing long drives (Pune - Nashik ... 210km) pretty regularly. But in last 3 years, there was not even one drive when I took someone along. But this time, Swati would be with me! I was thinking about a lot of worst case scenarios ...
its a long drive. she has never done this before. would she be comfortable? what would happen if the tyre goes bust in the middle of nowhere? what would happen if we meet with some accident? etc. etc. etc. Actually I always think of such worst case scenarios when I start for Nashik. But then, I am always alone, and don't have to think about anyone else but myself. But things are different when someone ... your wife ... your love is going to be with you :-)

well ... in spite of all these negative thoughts, I decided to give it a try. and there we were ... at 6.30 in the morning ... on our way to Mahabaleshwar!