How to calculate log2 of any number?

10 09 2008

Few days back, my client give me one 4 inch long and 2 inch wide math equation to implement. Well, the equation contains log2 and while coding, my Visual Assist was not auto filling the log2 function. It just underlines the function by redline. When i checked the MSDN, I was shocked that log2 is not available as the part of standard library. So how to get the log2 of a number?

Log2 is pretty simple, nah? Its implementation as follows,

#include <math.h>
// Calculates log2 of number.
double Log2( double n )
    // log(n)/log(2) is log2.
    return log( n ) / log( 2 );

Its silly function, But I still blame standard library for not including it. Because I’m lazy. 😉

Targeted Audience – Beginners.

How to import dialogs or resources from one project to another?

9 09 2008

Designing dialogs – that could grab a good amount of time! But often we can find dialogs that can be reused from our previous projects. But the copy paste trick – the Ctrl+C & Ctrl+V won’t work on dialog resources. So how to copy/paste dialogs or any other resources from one project to another?


Assume you have two projectsProject1 and project2 and you want to copy one dialog from Project1 to Project2. Just follow the steps –

For Visual Studio 6.0
1) Load project2 workspace in visual studio.
2) Now Browse and load Project1’s rc file. While opening resource file, select “Open As” as “Resources”.

3) Now drag your required dialog from project1’s resource tree and drop it to your resource tree.

4) You’ve successfully copied dialog from one project to another!

For Visual Studio 2005 and siblings
1) Open your IDE without any solutions loaded.
2) open both RC files into the IDE.
3) Now take Project2 RC file, right click on the dialog you want to export and copy it.


4) Now take Project1 RC file, right click and paste.


5) You see, now the dialog is imported from project1 to Project2.


Well, special thanks to Mike and Alan for their contribution for the trick in Visual Studio 2005.

You could also edit the rc file in some text editor and can copy paste the dialog if you’re a geek. 😉

Targeted Audience – Beginners.