#include <iostream>
using namespace std;

int msb(int x) {
    union { double a; int b[2]; };
    a = x;
    return (b[1] >> 20) - 1023;
}

int highestOneBit(int i) {
    // HD, Figure 3-1
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - ((unsigned)i >> 1);
}

int main() {
    double t1, t2;
    const int lim = 200 * 1000 * 1000;
    {
    	t1 = clock();
    	for (int i = 0; i < lim; i++) {
			int t = msb(i);
			if (t == -42) return 1;
		}
		t2 = clock();
		cout << (t2 - t1) / 1000.0 << endl;
    }
    {
    	t1 = clock();
    	for (int i = 0; i < lim; i++) {
			int t = highestOneBit(i);
			if (t == -42) return 1;
		}
		t2 = clock();
		cout << (t2 - t1) / 1000.0 << endl;
    }
}
