December 12, 2001

Counting Bits Efficiently

Sometimes you need to know the number of bits set in a word. I often see code to count the number set bits written as a loop, processing one bit at a time. There is a much faster method that uses a few statements of straight-line code.You can think of

Using the Template Argument as the Superclass

When you need to add the same member function to several classes, you can use a template class, derived from its template argument. template class T : public P {public: void f() { cout

Finding the Time in Different Zones

These days, many enterprises exchange data using a request/response approach. This data typically contains the date and time information regarding when a request was generated/received or a response generated/received. If they are in different time zones the following code/query can help in finding out the times in their respective zones.

Scripting All the Elements of a Particular Kind Using DOM

In DOM compliant browsers (IE5 & NS6), you can handle attributes of all similar elements with the getElementByTagName() function. For example, to change the background color of all the cells in a table you can use the following script:

Customizing Column Name and Width

SQL*Plus uses column names as default column headings while displaying query results. You can customize your own column heading and width with the help of following commands. To assign a new column heading, use the following command syntax: column heading ;e.g. column ename heading EmpName; To set the width of

The Effects of Deleting an Array of Pointers

Suppose we have a class called A. A has a data member p which is a pointer to another object: class A{public: A() {p = new B[10];}private: int *p;}; We also have an array of A objects that was allocated using new: A * arr = new A[10]; The question

Improving Large Strings’ Performance

Certain applications make use of very long strings. For example, a single string may contain generated HTML pages, a chapter of a book, a textual database and so on. Usually, the application repeatedly concatenates new substrings to the original string. Consequently, the string must frequently reallocate storage to make room