Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding MSB in bit string

12 views
Skip to first unread message

Tom Cunningham

unread,
Nov 5, 1986, 5:44:00 PM11/5/86
to
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

0 new messages