Finding MSB in bit string
Tom Cunningham
tomc at oakhill.UUCP
Thu Nov 6 08:44:00 AEST 1986
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
More information about the Comp.lang.c
mailing list