[net.lang.c] Finding MSB in bit string

tomc@oakhill.UUCP (Tom Cunningham) (11/06/86)

Hopefully this won't get ignored after my last admittedly dumb posting
(re: conversion in printf; thanks for the *civil* replies).  I want to
find the MSB in a bit string without having to do a series of shifts.
Only the single bit in place needs to be isolated, to be used for example
in a powers-of-2 switch.  Finding the LSB in this way is no problem:

	unsigned i, t;

	t = -i;
	i &= t;
	switch (i) {
	case 1:
	case 2:
	case 4:
	case 8:
		.
		.
		.
	}

Any equivalent way to do this to get the MSB?

Tom Cunningham     "Good, fast, cheap -- select two."
USPS:  Motorola Inc.  6501 William Cannon Dr. W.  Austin, TX 78735-8598
UUCP:  {ihnp4,seismo,ctvax,gatech}!ut-sally!oakhill!tomc
Phone: 512-440-2953