My first post from blackberry storm. Yeah I know its an old BB with more haters than lovers, but guess what? Its my first berry and I’m loving it, though my next phone will most likely be an android device.
My first post from blackberry storm. Yeah I know its an old BB with more haters than lovers, but guess what? Its my first berry and I’m loving it, though my next phone will most likely be an android device.
A classic problem asked in many interviews and such. And almost every genius will tell you that its simple.
swap(int *x,int *y)
{
*x += *y;
*y = *x - *y;
*x = *x - *y;
}
Simple right? Wrong!
what happens if one value is 2147483647 and the other is 2147483640 ?
You will definitely overflow x and make a mess of it!
So whats the foolproof way? Observe!
swap(int *x, int *y)
{
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
So how is it done? Bit-wise Xor operation. Faster, better and guaranteed to get you laid. For more info on bit wise xor Google it or click here
Technorati Tags: C, Variable swap, Bit operations

void printBinary(int *intVal){
register unsigned int mask;
mask = 1<<((8*sizeof(int))-1);
do
print("%d",((*intVal & mask)/mask));
while((mask >>= 1) & -1);
}
Ok, Sorry I did not put any comments in the code, simply because I want it to look short and sweet. Now let me elaborate a bit on how this works.
void printBinary(int *intVal){
We are taking a pointer here, so make sure your calling function sends an address and not the value.
register unsigned int mask;
Register for speed, we need to have an unsigned int.
mask = 1<<((8*sizeof(int))-1);
Ok, let me explain this one step at a time
Step 1: Get Size of integer.
Step 2: Multiply it with 8 ( we need the Size in Bits, not in bytes).
Step 3: Subtract this value by 1
Step 4 : Left Shift 1 by the value obtained by Step 3 calculation.
How does this work?
Assume that the platform where you are gonna run this code represents binary as 4bytes. So
Step 1: 4 Bytes
Step 2 : 4×2 = 32 Bits
Step 3 : 32 -1 = 31
Step 4 : Left shift 1 (binary : 00000000000000000000000000000001) by 31 times = binary : 10000000000000000000000000000000
do
print("%d",((*intVal & mask)/mask));
while((mask >>= 1) & -1);
Now comes the bit tricky part, so how do we do this? Quite simple once you get a hang of it.
First we do a bitwise and on the value we got from the calling function and the mask. We then divide it by mask.
Initially, the mask will be at the leftmost position (which is usually the sign bit, hence will be 1 if the value is negative). Now if the number you passed on was signed and negative, then ‘and’ing with mask will ensure that only signed bit will remain and makes the rest of the bits as ’0′. Now you divide this value by mask itself. Hence you will get value with 1.
Now if the bit was zero then the result of ‘and’ing would have been all zeros. Thus dividing the value with mask would have yielded 0.
Ok, now the next step, we right shift the mask by 1. So we will end up with 01000000000000000000000000000000 , first time around. We then do a bitwise and with -1 which is represented as binary all 1′s. Thus this while loop will remain true till we keep right shifting 1 in the mask all the way to the right, and finally dropped. By that time we would have printed the value of referenced by intVal pointer in binary form.
Simple?
Tip: If you know the size of integer in your platform then you can get some more performance and simplicity by pre calculating what number will be 1 followed by all zeros. For 4 bytes this value will be 2147483648.
Loved Cscope on cygwin, but hated the fact that you anything you select will open up in Vi, and then do some keyboard voodoo to get back to the cscope window?
Or are you one of those fan of notepad++ awesomeness but love the way cscope hunts for stuff for ya?
Fear not, there is a way both your sweethearts can now play with you, all at the same time for an awesome threesome
Just export these lines before you fire up Cscope
export CSCOPE_EDITOR="/cygdrive/c/Program Files/Notepad++/notepad++.exe" export CSCOPE_LINEFLAG="-n%s"
Please note : Change the CSCOPE_EDITOR path to where your notepad++ is currently residing. For your convenience, I have included the path that is default for Normal install of notepad++.
Better still, put it in a script file (or perhaps bashrc).
Got a better suggestion? Post a comment
Just managed to pull up Windows 7 RC1 from microsoft website. I immediately managed to installed it to my laptop ( I had to kill my Fedora 10 install in favour of Windows 7
, But I do have a copy of turnkey linux installed in my Vista under virtual box
). I have kept my vista Intact. Coming from Vista, here are my initial impressions (Approx 4 hours of usage). BTW, I have a Vaio CR35G/R ( Core2 Duo T8100 2.10 Ghz, 2GB DDR2 RAM, Intel 965 Mother Board, ATI Radeon X2300 Card with 128MB on board).
All in all Microsoft seems to have go it right this time around. I will seriously consider purchasing this once it comes out. ( And no, Microsoft is not paying me to say this :p, though if they sponsor me a desktop with Nvidia GTX 250 or ATI HD 4750, I can say how well Windows 7 will do on gaming front.
).
If you have anything to add (Good/bad/ugly things about windows 7), feel free to post em in the comments section.
Leaves in rain by ~allajunaki on deviantART
Hit up “Download” link at deviantART for getting the full res snap
Most of the corporate executives are hooked to their blackberries and its push mail service. However, blackberry service is expensive (at least here in India). Fret not folks, Seven is here to answer our prayers. Seven is a service that enables push mail for most of public domain email service providers (like gmail, yahoo, hotmail etc.). But wait, there is more, Seven can enable push mail for corporate e-mail which has OWA (like the organization that I work
).
I now get mails from office quite easily. I have also set up my gmail account for push. Now mails are delivered almost instantly to my Phone. Though I can get push mail with E90′s IMAP support (and gmail IMAP’s IDLE feature), I would still prefer SEVEN’s solution. Here are a few reasons.
Having said, there are a few observations.
Overall, I have been using it since yesterday, I think seven is an application worth keeping. If you are interested then head over to www.seven.com for getting a copy of beta client.
Just out of curiosity I ran Windows assessment of Windows 7 running in virtualbox (with VT-x enabled) and Vista. Here is a screen shot of the comparison.
What was amazing is the Hard disk Score, Virtualbox HDD is faster than the native disk !! Processor score is not too shabby, but I expected more with VT-x turned on. So how much does VT-x have influence on the Virtualbox performance? I tried to do the same score with VT-x turned “OFF”.
To my surprise, I got the same score! Perhaps, the windows assessment tool does not run any ring-0 code ( as far as I know, VT-x helps better management of ring-0 code).
Anyhow I’m posting the screen shot of the windows 7 on virtualbox with VT-x turned off.
If Anybody has a better idea as to why VT-x failed to change the scores in windows 7 assessment, please feel free to comment
I was browsing through wordpress blogs and I came across a post that posted this youtube video. I liked the comment on the part where he is routing to go somewhere on surface.
Due credit goes to : http://burnsar.wordpress.com/2007/06/23/microsoft-surface-video-spoof/ ( I saw this video there first
)