Books & Tools Techniques

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

Jude

Jude is my Java documentation browser. It combines Sun's definitive javadocs with the easy-to-use format of Java in a Nutshell, and tops it off with easy keyboard-based navigation and full-text searching.

Jude is available for free evaluation.

See the user's guide for more info

Java in a Nutshell

The 5th edition is now out, with complete coverage of Java 5.0!

It includes a fast-paced tutorial on the language, and a compact quick-reference for the core Java API.

Java Examples in a Nutshell

The 3rd edition, updated for Java 1.4

This edition has all-new coverage of the NIO and JavaSound APIs, completely rewritten Servlets and XML chapters, and coverage of new Java 1.4 features (assertions, logging, preferences, SSL, etc.) added througout. A great book for those who like to learn by example. 193 working examples: 21,900 lines of carefully commented code to learn from.

Java 1.5 Tiger: A Developer's Notebook

Amazon incorrectly credits me as the main author on this book. I'm actually the second author: really more of a consultant. This is a good book about all the language changes in the latest version of Java.

Effective Java

I didn't write this excellent book, but I wish I had.

Author Josh Bloch is probably best known for the collections classes in the java.util package. His experience and wisdom are apparent in this book. I learned from it and recommend it highly.

July 12, 2004

More Fun with Bits

The method below multiplies a float by 2 by manipulating its bits to increment the exponent. See the javadoc for Float.intBitsToFloat() for details on the IEEE754 floating-point representation. Unlike the previous blog entry, the methods used here have been around a long time.

static float multiplyByTwo(float x) {
    // View the float as 32 bits
    int bits = Float.floatToIntBits(x);
    // Extract the bits that represent the exponent
    int exponent = (bits >> 23) & 0xFF;
    // clear the exponent bits
    bits &= ~(0xFF << 23);
    // Increment the exponent and set this new value
    bits |= ((exponent+1) & 0xFF) << 23;
    // Return the bits as a float
    return Float.intBitsToFloat(bits);
}

Bit Tricks

Java 1.5 defines new bit-manipulation methods on Integer and Long. These are one of the minor changes attributable to Josh Bloch. Here's some code to play around with them.

static void bitTricks(int x) {
    // Approximate log2() with numberOfLeadingZeros()
    if (x > 0) 
	System.out.printf("base-2 log of %d is between %d and %d%n", x,
			  Integer.SIZE-1-Integer.numberOfLeadingZeros(x),
			  Integer.SIZE-Integer.numberOfLeadingZeros(x-1));

    // If 1 bits in an int are used to represent members of a set, then
    // bitCount() and highestOneBit() allow efficient counting and
    // iteration of the members of the set
    System.out.printf("%d has %d bits set.%n", x, Integer.bitCount(x));
    System.out.print(x + " = ");
    while(x != 0) {
	int highbit = Integer.highestOneBit(x);  // Get the highest bit
	System.out.print(highbit + "+");         // Print it out
	x &= ~highbit;                           // Clear it
    }
    System.out.println("0");
}

Advertising
About
Store
Search
Google
Web this site
Archives
Syndicate

Powered by
Movable Type